Hosting Django Web Application as an application on an existing website
I hosted a django web app on IIS using wfastcgi and it was successful when hosted as a new website using the configuration details below. What would I need to do differently on these configurations if I want to host the very app as an application to an existing IIS website on production. I have tried copying the very configuration and placing it it in the root of the IIS application but finding error 500 - internal server error. The IIS user already has read, execute and edit permissions on the app folder.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="WSGIHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\pathtopython\Scripts\python.exe|C:\pathtowfastcgi\Scripts\wfastcgi.py" resourceType="Unspecified" />
</handlers>
<rewrite>
<rules>
<rule name="Django" stopProcessing="true">
<match url=".*" />
<action type="Rewrite" url="http://localhost:8000/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
When hosting a Django web app as an application to an existing IIS website, there are several considerations and modifications you need to make to your configuration to ensure it works correctly within the context of the existing site. Here are the key steps and adjustments:
Application Path and Handler Configuration:
Ensure the application path is correctly set in the handler and that it points to the correct Python and wfastcgi.py scripts.
Application-Specific Rewrite Rules:
Modify the rewrite rules to accommodate the application path and ensure that URLs are correctly rewritten within the context of the existing website.
Permissions and Configuration Scope:
Confirm that the IIS application has the necessary permissions and the configuration scope is correct.
Here is an example configuration adjusted for hosting as an application within an existing website:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<!-- Adjust the path to your Python and wfastcgi.py scripts accordingly -->
<add name="WSGIHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\pathtopython\Scripts\python.exe|C:\pathtowfastcgi\Scripts\wfastcgi.py" resourceType="Unspecified" />
</handlers>
<rewrite>
<rules>
<!-- Ensure the URL rewrite rule points to the correct port and respects the application path -->
<rule name="Django" stopProcessing="true">
<match url=".*" />
<!-- Adjust the URL rewrite action to point to the application's local server address -->
<action type="Rewrite" url="http://localhost:8000/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>