2015-02-07 117 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" /> 

希望這會解決您的問題。 :)