IIS部署Django

按照順序部署

1.安裝數據庫
2.安裝數據庫客戶端【SSMS】
3.安裝Python
4.安裝IIS
5.安裝CGI

6.將源碼拷貝至【C:\inetpub\wwwroot\MySite】

  (MySite是自定義文件夾,wwwroot是IIS默認網站存放的文件夾,爲避免權限問題,不建議變動)

7.cmd 執行:pip install -r requirements(安裝依賴包)

8.cmd 執行:pip install wfastcgi

9.cmd 執行:wfastcgi-enable(獲取腳本處理器信息,第8步需要使用)
  【scriptProcessor】
    結構:<Python安裝路徑>\python.exe|<Python安裝路徑>\lib\site-packages\wfastcgi.py
    例如:【d:\programs\python\python.exe|d:\programs\python\lib\site-packages\wfastcgi.py】

7.打開IIS管理器添加網站,網站名稱爲【MySite】,物理路徑爲【C:\inetpub\wwwroot\MySite】,選擇IP和端口

8.在【C:\inetpub\wwwroot\MySite】文件夾下添加文件【web.config】,內容如下(【】內是需要替換的部分):

複製代碼

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <configuration>
 3     <system.webServer>
 4         <handlers>
 5             <add name="Python FastCGI" 
 6                     path="*" 
 7                     verb="*" 
 8                     modules="FastCgiModule" 
 9                     scriptProcessor="【d:\programs\python\python.exe|d:\programs\python\lib\site-packages\wfastcgi.py】" 
10                     resourceType="Unspecified" 
11                     requireAccess="Script"/>
12         </handlers>
13     </system.webServer>
14     <appSettings>
15         <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
16         <add key="PYTHONPATH" value="【C:\inetpub\wwwroot\MySite】" />
17         <add key="DJANGO_SETTINGS_MODULE" value="【項目名.settings】" />
18     </appSettings>
19 </configuration>

複製代碼

9.在網站【MySite】添加【static】虛擬目錄

10.在【C:\inetpub\wwwroot\MySite\static】文件夾下添加文件【web.config】,內容如下:

複製代碼

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

複製代碼

11.在網站【MySite】添加【media】虛擬目錄
12.在【C:\inetpub\wwwroot\MySite\media】文件夾下添加文件【web.config】,內容如下:

複製代碼

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <configuration>
 3     <system.webServer>
 4         <!-- this configuration overrides the FastCGI handler to let IIS serve the static files -->
 5         <handlers>
 6             <clear/>
 7             <add name="MediaFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
 8         </handlers>
 9     </system.webServer>
10 </configuration>

複製代碼

 

權限相關的報錯,執行如下三步:
13.cmd 執行:%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers
14.cmd 執行:%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/modules
15.右鍵點擊【MySite】,點擊【編輯權限】,在【安全】選項卡里給IIS_IUSERS賦予【完全控制】的權限

 

 

發佈了94 篇原創文章 · 獲贊 10 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章