4

I'm currently using a standard Web Site on Microsoft Azure to host a web.py website.

In web.py the convention is to make a directory called /static to host static files such as images, css and javascript. In my local environment this works just fine.

However, when I deploy to Microsoft Azure my static content returns an Error 404. When I look at the directory via FTP i can see that the files are all present and correct.

I have a feeling this is something to do with the fact that my local installation doesn't require the use of wsgi, however the hosting on IIS on Azure does.

I found on the Microsoft Azure python documentation that you can use a web.config file to serve static content without having to use the web.py server, which would be faster and might resolve this issue, however that doesn't seem to have resolved the issue.

Any and all help would be appreciated. Below you can see my webapp.py and web.config files.

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>

2 Answers 2

0

You need to add a mime type the "non-standard" types you need returned.

Example: for ogg, m4a, and pdf, you would add the following config.xml in the root of your web. If a config.xml already exists merge the section in. A full list of extensions and their mimeTypes can be found at 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>

Hope this helps. Healy in Tampa

0

I had the same problem. Try the following modification:

Replace

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

With these lines:

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

Hope this solve your problem. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.