【发布时间】:2017-12-30 17:38:25
【问题描述】:
我想部署托管在 Azure Web 应用程序中的 Django 网站。
静态文件在 DEBUG 模式 (DEBUG=False) 下完美提供,但我找不到正确的设置让服务器在生产中处理它。我所有的静态文件都收集在应用根目录 wwwroot/static/ 的“静态”目录中。
这是 web.config,位于应用程序的根目录。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="MyApp.wsgi.application" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\python.exe" />
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()" />
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
<add key="DJANGO_SETTINGS_MODULE" value="MyApp.settings" />
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgit.log"/>
</appSettings>
<system.webServer>
<handlers>
<add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
我还在静态目录中添加了以下web.config:
<?xml version="1.0"?>
<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,DefaultDocumentModule,DirectoryListingModule"
resourceType="Either"
requireAccess="Read" />
</handlers>
</system.webServer>
我还在网络应用设置中将静态目录定义为“虚拟目录”,其中“\static”指的是“\site\wwwroot\static”,并选中“应用程序”复选框(我也尝试离开它没有被选中,但它不会改变任何东西。
但是,这不起作用。
1) 是否可以在不使用 CDN 的情况下设置 Azure Web 应用以在生产中提供静态文件?
2) 如果是,该怎么做?
【问题讨论】:
-
您遇到的错误是什么?
-
静态文件(css,js)没有提供,所以空白的html页面。