Django上线部署之IIS

环境:
  1.Windows Server 2016 Datacenter 64位
  2.SQL Server 2016 Enterprise 64位
  3.Python 3.6.0 64位
  4.administrator用户,无域环境,最高权限

要求:
  按照顺序部署

 

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>
View Code

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>
View Code

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>
View Code

 

权限相关的报错,执行如下三步:
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赋予【完全控制】的权限

转载于:https://www.cnblogs.com/Siriusmath/p/11392625.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值