Saturday 14 September 2013

web.py + uwsgi - custom 404 not working

web.py + uwsgi - custom 404 not working

I tried googling and browsing around but wasn't able to find an answer, so
apologies if this question has already been answered somewhere.
I'm unable to serve custom 404 pages when using uwsgi + nginx for web.py
applications. Using web.py server everything works as it should, but while
using nginx I'm only getting the default web.py 'not found' page.
Could anyone point me in the right direction here?
My configs:
nginx:
server {
listen 80;
set $webappsdir /srv/www/webapps/;
server_name *.devserver.local;
if ($host ~* ^(.*)\.devserver\.local$) {
set $appname $1;
}
location /static/ {
try_files $uri =404;
}
location /templates/ {
try_files $uri =404;
}
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi_vhosts.sock;
uwsgi_param UWSGI_CHDIR /srv/www/webapps/$appname;
uwsgi_param UWSGI_PYHOME /srv/www/webapps/$appname;
uwsgi_param UWSGI_SCRIPT index;
}
}
/srv/www/webapps/example/index.py:

import web
urls = (
'/', 'index'
)
app = web.application(urls, globals())
app.notfound = notfound
class index:
def GET(self):
return "Hello, world!"
def notfound():
return web.notfound("404. Not found")
if __name__ == "__main__": app.run()
application = app.wsgifunc()

Thanks in advance, Jakub

No comments:

Post a Comment