2015-02-07 76 views
4

我目前在Microsoft Azure上使用标准网站来托管web.py网站。如何在Microsoft Azure上使用web.py提供静态内容?

在web.py惯例是创建一个名为/static举办静态文件,如图像,CSS和JavaScript目录。在我的本地环境中,这工作得很好。

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

我有一种感觉,这是值得做的事实,我的本地安装不需要使用WSGI的,但是托管在IIS在Azure上做。

我在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> 

回答

0

您需要添加一个MIME类型,你需要返回的 “非标准” 的类型。

示例:对于ogg,m4a和pdf,您可以将以下config.xml添加到Web的根目录中。如果config.xml已经存在,则合并该部分。完整的扩展列表及其MIME类型可在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> 

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

0

我有同样的问题。请尝试以下修改:

更换

<remove name="Python273_via_FastCGI" /> 
    <remove name="Python340_via_FastCGI" /> 

有了这些行:

<remove name="Python27_via_FastCGI" /> 
    <remove name="Python34_via_FastCGI" /> 

希望这会解决您的问题。 :)