gpt4 book ai didi

python - 如何在 Microsoft Azure 上使用 web.py 提供静态内容?

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:57 25 4
gpt4 key购买 nike

我目前正在 Microsoft Azure 上使用标准网站来托管 web.py 网站。

在 web.py 中,约定是创建一个名为 /static 的目录来托管静态文件,例如图像、css 和 javascript。在我本地的环境中,这工作得很好。

但是,当我部署到 Microsoft Azure 时,我的静态内容返回错误 404。当我通过 FTP 查看目录时,我可以看到文件都存在并且正确。

我有一种感觉,这与我的本地安装不需要使用 wsgi 有关,但 Azure 上的 IIS 上的托管则需要。

我在 Microsoft Azure python 文档中发现,您可以使用 web.config 文件来提供静态内容,而无需使用 web.py 服务器,这会更快并且可能会解决此问题,但这似乎并不可行已解决问题。

任何和所有帮助将不胜感激。下面您可以看到我的 webapp.py 和 web.config 文件。

webapp.py

import web
render = web.template.render('templates/')

urls = (
'/', 'index',
'/feed', 'feed'
)
app = web.application(urls, globals(), autoreload=False)

class index:
def GET(self):
return render.index()

class feed:
def GET(self):
return 'The RSS feed of all the blogs on CS Blogs will appear here'

# If this file is being ran as the main program, start the web app.
if __name__ == "__main__":
app.run()

# This function allows azure to hook up the correct URLs to the correct functions
def wsgiHandler():
return web.application(urls, globals(), autoreload=False).wsgifunc()

web.config

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="webapp.wsgiHandler()" />
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="Python273_via_FastCGI" />
<remove name="Python340_via_FastCGI" />
<add name="Python FastCGI"
path="handler.fcgi"
verb="*"
modules="FastCgiModule"
scriptProcessor="D:\Python27\python.exe|D:\Python27\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" />
<conditions>
</conditions>
<action type="Rewrite"
url="handler.fcgi/{R:1}"
appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

最佳答案

您需要添加您需要返回的“非标准”类型的 mime 类型。

示例:对于 ogg、m4a 和 pdf,您可以在网站的根目录中添加以下 config.xml。如果 config.xml 已存在,请合并该部分。扩展及其 mimeType 的完整列表可以在 http://www.feedforall.com/mime-types.htm 中找到。 .

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".m4a" />
<mimeMap fileExtension=".m4a" mimeType="audio/mp4a-latm"/>
<remove fileExtension=".ogg" />
<mimeMap fileExtension=".ogg" mimeType="application/ogg"/>
<remove fileExtension=".pdf" />
<mimeMap fileExtension=".pdf" mimeType="application/pdf"/>
</staticContent>
</system.webServer>
</configuration>

希望这有帮助。希利在坦帕

关于python - 如何在 Microsoft Azure 上使用 web.py 提供静态内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28377037/

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