You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/python/configure-web-apps-for-iis-windows.md
+27-27Lines changed: 27 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: Configure Python web apps for IIS
2
+
title: Configure Python Web Apps for IIS
3
3
description: Configure Python web apps to run with Internet Information Services (IIS) from a Windows virtual machine by specifying settings in their web.config files.
4
-
ms.date: 04/18/2024
4
+
ms.date: 07/28/2025
5
5
ms.topic: how-to
6
6
author: cwebster-99
7
7
ms.author: cowebster
@@ -13,25 +13,25 @@ ms.subservice: python
13
13
14
14
# Configure Python web apps for IIS
15
15
16
-
When you use Internet Information Services (IIS) as a web server on a Windows computer (including [Windows virtual machines on Azure](/azure/architecture/reference-architectures/n-tier/windows-vm)), you need to configure the Python web application to enable IIS to properly process Python code. The configuration is accomplished through settings in the `web.config` file for the Python web app. This article describes how to configure the necessary settings.
16
+
When you use Internet Information Services (IIS) as a web server on a Windows computer (including [Windows virtual machines on Azure](/azure/architecture/reference-architectures/n-tier/windows-vm)), you need to configure the Python web application to enable IIS to properly process Python code. The configuration is accomplished through settings in the *web.config* file for the Python web app. This article describes how to configure the necessary settings.
17
17
18
18
## Prerequisites
19
19
20
-
- Python on Windows installed. To run a web app, first install your required version of Python directly on the Windows host machine as described on[Install Python interpreters](installing-python-interpreters.md).
20
+
- Python on Windows installed. To run a web app, first install your required version of Python directly on the Windows host machine as described in[Install Python interpreters](installing-python-interpreters.md).
21
21
22
-
- Identify the location of the `python.exe` interpreter. For convenience, you can add that location to your PATH environment variable.
22
+
- Identify the location of the *python.exe* interpreter. For convenience, you can add that location to your PATH environment variable.
23
23
24
24
- Required packages installed. For a dedicated host, you can use the global Python environment to run your app rather than a virtual environment. Accordingly, you can install all of your app's requirements into the global environment by running the `pip install -r requirements.txt` command.
25
25
26
26
## Set web.config to point to the Python interpreter
27
27
28
-
The `web.config` file for your Python application instructs the IIS web server (version 7 or later) running on Windows about how it should handle Python requests through HttpPlatformHandler (recommended) or FastCGI. Visual Studio versions 2015 and earlier make these modifications automatically. For Visual Studio 2017 and later, you must modify the `web.config` file manually.
28
+
The *web.config* file for your Python application instructs the IIS web server (version 7 or later) running on Windows about how it should handle Python requests through HttpPlatformHandler (recommended) or FastCGI. Visual Studio versions 2015 and earlier make these modifications automatically. For Visual Studio 2017 and later, you must modify the *web.config* file manually.
29
29
30
-
If your project does not already contain a `web.config` file, you can add one by right-clicking the project directory, selecting **Add > New Item** and searching for `web.config` or creating a blank `web.config` XML file.
30
+
If your project doesn't already contain a *web.config* file, you can add one by right-clicking the project directory, selecting **Add > New Item** and searching for *web.config* or creating a blank *web.config* XML file.
31
31
32
-
### Option 1: Configure the HttpPlatformHandler
32
+
### Option 1: Configure the HttpPlatformHandler
33
33
34
-
The HttpPlatform module passes socket connections directly to a standalone Python process. This pass-through allows you to run any web server you like, but it requires a startup script that runs a local web server. This approach is commonly done by using a Python web framework, such as Flask or Django. You specify the script in the `<httpPlatform>` element of the `web.config` file. The `processPath` attribute points to the site extension's Python interpreter. The `arguments` attribute points to your startup script that runs a local web server, in this case `runserver.py`, and any arguments you want to provide:
34
+
The HttpPlatform module passes socket connections directly to a standalone Python process. This pass-through allows you to run any web server you like, but it requires a startup script that runs a local web server. This approach is commonly done by using a Python web framework, such as Flask or Django. You specify the script in the `<httpPlatform>` element of the *web.config* file. The `processPath` attribute points to the site extension's Python interpreter. The `arguments` attribute points to your startup script that runs a local web server, in this case *runserver.py*, and any arguments you want to provide:
35
35
36
36
```xml
37
37
<?xml version="1.0" encoding="utf-8"?>
@@ -56,18 +56,18 @@ The HttpPlatform module passes socket connections directly to a standalone Pytho
56
56
57
57
In this example, the `HTTP_PLATFORM_PORT` environment variable contains the port that your local server should listen on for connections from `localhost`. This example also shows how to create another environment variable, `SERVER_PORT`. You can create and assign environment variables as needed.
58
58
59
-
### Option 2: Configure the FastCGI handler
59
+
### Option 2: Configure the FastCGI handler
60
60
61
-
Alternatively, you can use FastCGI to configure your apps. FastCGI is an interface that works at the request level. IIS receives incoming connections and forwards each request to a WSGI app running in one or more persistent Python processes.
61
+
Alternatively, you can use FastCGI to configure your apps. FastCGI is an interface that works at the request level. IIS receives incoming connections and forwards each request to a Web Server Gateway Interface (WSGI) app running in one or more persistent Python processes.
62
62
63
63
> [!NOTE]
64
-
> Although you can set your project up using FastCGI, we recommend using **HttpPlatformHandler** to configure your apps, as the [WFastCGI](https://pypi.org/project/wfastcgi/) project is no longer maintained and may result in bugs.
64
+
> Although you can set up your project using FastCGI, we recommend using **HttpPlatformHandler** to configure your apps because the [WFastCGI](https://pypi.org/project/wfastcgi/) project is no longer maintained and might result in bugs.
65
65
66
66
To use FastCGI, first install and configure the wfastcgi package as described in [pypi.org/project/wfastcgi/](https://pypi.io/project/wfastcgi).
67
67
68
-
Next, modify your application's `web.config` file to include the full paths to the `python.exe` executable and the `wfastcgi.py` file in the `PythonHandler` key. The following steps assume Python is installed in the *c:\python36-32* folder and the app code is in the *c:\home\site\wwwroot* folder. Adjust these values for your paths accordingly.
68
+
Next, modify your application's *web.config* file to include the full paths to the *python.exe* executable and the *wfastcgi.py* file in the `PythonHandler` key. The following steps assume Python is installed in the *c:\python36-32* folder and the app code is in the *c:\home\site\wwwroot* folder. Adjust these values for your paths accordingly.
69
69
70
-
1. Modify the `PythonHandler` entry in the `web.config` file so the path matches the Python install location. For more information, see [IIS Configuration Reference](https://www.iis.net/configreference) (iis.net).
70
+
1. Modify the `PythonHandler` entry in the *web.config* file so the path matches the Python install location. For more information, see [IIS Configuration Reference on iis.net](https://www.iis.net/configreference).
71
71
72
72
```xml
73
73
<system.webServer>
@@ -79,7 +79,7 @@ Next, modify your application's `web.config` file to include the full paths to t
79
79
</system.webServer>
80
80
```
81
81
82
-
1. Within the `<appSettings>` section of the `web.config` file, add keys for `WSGI_HANDLER`, `WSGI_LOG` (optional), and `PYTHONPATH`:
82
+
1. Within the `<appSettings>` section of the *web.config* file, add keys for `WSGI_HANDLER`, `WSGI_LOG` (optional), and `PYTHONPATH`:
83
83
84
84
```xml
85
85
<appSettings>
@@ -96,25 +96,25 @@ Next, modify your application's `web.config` file to include the full paths to t
96
96
- The `WSGI_HANDLER` key must point to a WSGI app importable from your app.
97
97
- The `WSGI_LOG` key is optional, but the key is recommended for debugging your app.
98
98
99
-
1. Set the `WSGI_HANDLER` entry in the `web.config` file as appropriate for the framework you're using:
99
+
1. Set the `WSGI_HANDLER` entry in the *web.config* file as appropriate for the framework you're using:
100
100
101
-
-**Bottle**: Add parentheses after the `app.wsgi_app` value as shown in this example. The parentheses are necessary because the object is a function rather than a variable. You can see the syntax in the `app.py` file.
101
+
-**Bottle**: Add parentheses after the `app.wsgi_app` value as shown in this example. The parentheses are necessary because the object is a function rather than a variable. You can see the syntax in the *app.py* file.
102
102
103
103
```xml
104
104
<!-- Bottle apps only -->
105
105
<addkey="WSGI_HANDLER"value="app.wsgi_app()"/>
106
106
```
107
107
108
-
- **Flask**: Change the `WSGI_HANDLER` value to `<project_name>.app` where `<project_name>` matches the name of your project. You can find the exact identifier by looking at the `from <project_name> import app` statement in the `runserver.py` file. For example, if the project is named `FlaskAzurePublishExample`, the entry appears as follows:
108
+
- **Flask**: Change the `WSGI_HANDLER` value to `<project_name>.app` where `<project_name>` matches the name of your project. You can find the exact identifier by looking at the `from <project_name> import app` statement in the *runserver.py* file. For example, if the project is named *FlaskAzurePublishExample*, the entry appears as follows:
109
109
110
110
```xml
111
111
<!-- Flask apps only: Change the project name to match your app -->
1. **Django apps only**: In the Django project's `settings.py` file, add your site URL domain or IP address to the `ALLOWED_HOSTS` entry. Replace '1.2.3.4' with your URL or IP address:
130
+
1. **Django apps only**: In the Django project's *settings.py* file, add your site URL domain or IP address to the `ALLOWED_HOSTS` entry. Replace '1.2.3.4' with your URL or IP address:
131
131
132
132
```python
133
133
# Change the URL or IP address to your specific site
@@ -137,17 +137,17 @@ Next, modify your application's `web.config` file to include the full paths to t
137
137
If you don't add your URL to the array results, you see the following error:
138
138
139
139
```output
140
-
DisallowedHost at / Invalid HTTP_HOST header: '\<site URL\>'. You might need to add '\<site URL\>' to ALLOWED_HOSTS.
140
+
DisallowedHost at / Invalid HTTP_HOST header: '<site URL>'. You might need to add '<site URL>' to ALLOWED_HOSTS.
141
141
```
142
142
143
-
When the array is empty, Django automatically allows `'localhost'` and `'127.0.0.1'` as hosts. If you add your production URL, these host sites aren't automatically allowed. For this reason, you might want to maintain separate development and production copies of the `settings.py` file, or use environment variables to control the runtime values.
143
+
When the array is empty, Django automatically allows `'localhost'` and `'127.0.0.1'` as hosts. If you add your production URL, these host sites aren't automatically allowed. For this reason, you might want to maintain separate development and production copies of the *settings.py* file, or use environment variables to control the runtime values.
144
144
145
145
## Deploy to IIS or a Windows virtual machine
146
146
147
-
When you have the correct `web.config` file in your project, you can publish to the computer that's running IIS from **Solution Explorer**. Right-click the project, select **Publish**, and then select **IIS, FTP, etc.**. In this situation, Visual Studio copies only the project files to the server. You're responsible for all server-side configuration.
147
+
When you have the correct *web.config* file in your project, you can publish to the computer that's running IIS from **Solution Explorer**. Right-click the project, select **Publish**, and then select **IIS, FTP, etc.**. In this situation, Visual Studio copies only the project files to the server. You're responsible for all server-side configuration.
0 commit comments