MSDN Documentation

Azure App Services - Configuration

Configuring Azure App Services

This section provides comprehensive guidance on configuring your Azure App Services to meet your application's needs. Effective configuration is crucial for performance, security, and scalability.

Application Settings

Application settings are key-value pairs that your application code can read. These are ideal for storing connection strings, API keys, and other environment-specific parameters.

  • Adding Settings: Navigate to your App Service in the Azure portal, go to "Configuration" under "Settings", and select the "Application settings" tab. Click "New setting".
  • Connection Strings: A dedicated tab for connection strings allows you to specify the type (e.g., SQL Azure, Custom) and the connection string value. These are masked for security.
  • Accessing Settings in Code: Most language runtimes provide methods to access application settings. For example, in C#: Environment.GetEnvironmentVariable("YourSettingName").

Example: Database Connection String

Name: DatabaseConnectionString

Value: Server=tcp:your_server.database.windows.net,1433;Database=your_db;User ID=your_user;Password=your_password;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

Slot Setting: (Optional) Check this if the setting should only apply to deployment slots.

General Settings

General settings control fundamental aspects of your App Service, including the .NET Framework version, PHP version, Java version, Web Sockets, Always On, and more.

  • Stack Settings: Choose the runtime stack and version for your application.
  • Platform: Select 32-bit or 64-bit for your application worker processes.
  • Always On: Keep your application loaded and ready to respond to requests, preventing cold starts. This is particularly important for demanding applications.
  • Web Sockets: Enable Web Sockets for real-time communication.
  • HTTP Version: Configure the preferred HTTP version (e.g., HTTP/1.1, HTTP/2).

Path Mappings

Path mappings allow you to configure virtual directories and applications within your App Service. This is useful for hosting multiple applications or static content under a single App Service.

  • Virtual Applications and Directories: Define paths and map them to physical directories or external storage.
  • Default Document: Specify the default file to serve when a directory is requested (e.g., index.html, default.aspx).

Custom Domains and TLS/SSL

Securing your application with custom domains and SSL certificates is essential. Azure App Services offers robust options for managing these.

  • Adding Custom Domains: Map your own domain names (e.g., www.yourcompany.com) to your App Service.
  • Uploading Certificates: Secure your custom domains with TLS/SSL certificates. You can upload your own or use Azure's free App Service managed certificates.
  • Enforcing HTTPS: Redirect all HTTP traffic to HTTPS for enhanced security.

Deployment Slots

Deployment slots are live apps with their own hostnames. They allow you to stage and test new versions of your app before swapping them into production. This minimizes downtime and risk.

  • Create a Slot: Add a new deployment slot from the "Deployment slots" section.
  • Swap Slots: Seamlessly swap your staging slot with your production slot.
  • Configuration: Settings can be applied to all slots or specific to a slot by marking them as "Slot Setting".

Key Configuration Concepts

Environment Variables: Application settings are often exposed as environment variables to your application.

App Settings vs. Connection Strings: While both store configuration, connection strings are often treated with higher security and specific handling by Azure.

Slot Settings: Crucial for managing environment-specific configurations (e.g., different database connection strings for staging vs. production).

Best Practices

  • Use application settings for all environment-specific configurations.
  • Avoid hardcoding secrets or credentials directly in your code.
  • Leverage deployment slots for safe deployments and rollbacks.
  • Keep your runtime stack and platform settings up-to-date.
  • Always enforce HTTPS for secure communication.