Use IIS to deploy Django project

Use IIS to deploy Django project

1. Systems and Software version: Windows Server 2008 Standard, IIS 7.0, Python3.6 + Django 2.0.4

. 2 python module mounted wfastcgi: pip install wfastcgi

3. After successful installation, open python Catalog -> Lib-> site-packages directory, copying files to wfastcgi.py Django project root directory;

4. Because the user rights and other issues, we recommend Django project folder to the C: \ inetpub \ wwwroot;

5. IIS site was added, and the port number of the physical path is provided;

6. Select the new site, selection handler mapping -> Add module mapping

       Request Path: *

       Module: FastCgiModule

       Executable file: xxxxxxxx | xxxxxxxxx

       Note: The first half is python.exe path, if you configure a virtual environment, for the python.exe path of the virtual environment.

       The second half is under inetpub \ wwwroot, to be published in the path wfastcgi.py Django project file.

       Request limit, check the box only if the request is mapped to the following when the call handler, select the file.

7. After the configuration, the root node select IIS, FastCGI selected set, adding the selection module mapping step, configure the environment variables

    Variables need to be added are three:

    Position (1) get_wsgi_application () method, C: \ administrator \ Lib \ site-packages \ django \ core \ wsgi.py

            Name: WSGI_HANDLER

           Value: django.core.wsgi.get_wsgi_application()

      (2) Django project directory

           Name: PYTHONPATH

          Value: C: \ inetpub \ wwwroot \ project name

     Location (3) project settings.py file

          Name: DJANGO_SETTINGS_MODULE

          Value: project name .settings

  In the project folder contents web.config file:

<?xml version="1.0" encoding="UTF-8"?>
 <configuration> <system.webServer> <handlers> <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="<Path to Python>\python.exe|<Path to file>\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/> </handlers> </system.webServer> <appSettings> <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" /> <add key="PYTHONPATH" value="<Path to Django App>" /> <add key="DJANGO_SETTINGS_MODULE" value="<Django App>.settings" /> </appSettings> </configuration>

 

8. Static configuration file: On the IIS deployment site, right-click the new virtual directory path for the static folder

  Built on a static folder web.config files and settings:

<?xml version="1.0" encoding="UTF-8"?>
<configuration> <system.webServer> <!-- this configuration overrides the FastCGI handler to let IIS serve the static files --> <handlers> <clear/> <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" /> </handlers> </system.webServer> </configuration>

 

9. After the above configuration should be run. Focus is on two web.config files, especially in the static web.config file folder, usually not covered.

10. Some notes:

  • Problem admin module missing styles appear in the actual deployment. The solution is in the static folder on the python file admin style directory copied.
  •  Use django auth log, after verifying a successful landing, the page will automatically jump to / account / profile, report the error page can not be found, it is necessary to set LOGIN_REDIRECT_URL = '/ index' in setting.py project, specify landing after a successful jump index page.
  • Note the folder, read-only permissions problem, usually encountered file.
  • Message HTTP 400 error - Invalid Request (Bad request), or access to the machine, can not be accessed using the IP address, because the set of problems allowed_hosts settings.py the first set ALLOWED_HOSTS = [ '*'] test, then Add the IP address or domain name.

Guess you like

Origin www.cnblogs.com/sdlyxyf/p/11370599.html
Recommended