2017年7月6日 星期四

Windows部屬執行IIS+Python/Django+wfastcgi

OS: Win7 SP1
Python: 3.6.0
Django: 1.11
wfastcgi: 3.0.0
Python路徑: c:\python\python.exe
Django APP路徑: C:\mulin\python crm
wfastcgi安裝後路徑: c:\python\lib\site-packages\wfastcgi.py

總是有ㄧ些因素,無法將Django部屬於Linux,只好透過IIS的wfastcgi將Django串在一起,請注意python manage.py runserver是給debug時後使用的,正式上線千萬別使用這個

1. 安裝wfastcgi並啟動它,建議直接切到該路徑C:\mulin\python crm

pip install wfastcgi

wfastcgi-enable

2. 我們在C:\mulin\python crm建立一個web.config的檔案裡面內容為,宣告handlers使用FastCGI模組,在appsettings宣告WSGI用django.core.wsgi.get_wsgi_application()"、pythonpath為C:\mulin\python crm、Django的app settings是在mysite的settings那

wfastcgi安裝後路徑: c:\python\lib\site-packages\wfastcgi.py
Python路徑: c:\python\python.exe

以上這兩個路徑要放入scriptProcessor

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>

        <system.webServer>
            <handlers>
                <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\python\python.exe|c:\python\lib\site-packages\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="C:\mulin\python crm" />
            <add key="DJANGO_SETTINGS_MODULE" value="mysite.settings" />
        </appSettings>
    </configuration>

3. 我們需要再放一個web.config到C:\mulin\python crm\static資料夾下面來讓她知道static還有ccs那些東西

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <system.webServer>
    <handlers>
      <remove name="Python FastCGI" />
    </handlers>
  </system.webServer>
</configuration>

4. 安裝IIS後並啟動CGI服務
















5. 在IIS下新增一個網站,port為8000,即為成功,記得實體路徑需選C:\mulin\python crm