gpt4 book ai didi

Django/Azure : serving static files in production

转载 作者:行者123 更新时间:2023-12-03 01:07:03 24 4
gpt4 key购买 nike

我想部署一个托管在 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)如果是,怎么做?

最佳答案

最好将静态内容移动到 Azure Blob 存储并使用 CDN 以获得更好的性能。

1-) 您可以像下面这样定义您的 web.config:https://github.com/prashanthmadi/azure-django-customdeployment/blob/master/web.config

2-) 配置静态文件处理程序,添加以下内容:https://stackoverflow.com/a/2066040/1384539

关于Django/Azure : serving static files in production,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45292372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com