【问题标题】:web.py + uwsgi - custom 404 not workingweb.py + uwsgi - 自定义 404 不起作用
【发布时间】:2013-09-19 06:55:58
【问题描述】:

我尝试用谷歌搜索和浏览,但无法找到答案,如果这个问题已经在某个地方得到解答,我们深表歉意。

在将 uwsgi + nginx 用于 web.py 应用程序时,我无法提供自定义 404 页面。 使用 web.py 服务器一切正常,但在使用 nginx 时,我只得到默认的 web.py 'not found' 页面。

谁能给我指出正确的方向?

我的配置:

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()

提前致谢, 雅库布

【问题讨论】:

    标签: python nginx web.py


    【解决方案1】:

    在我设法解决“问题”时回复自己。

    我更改了脚本,现在是这样的:

    if __name__ == "__main__": app.run()
    application = app
    application.notfound = notfound
    application = app.wsgifunc()
    

    一切似乎都运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-23
      • 2014-01-02
      • 1970-01-01
      • 2016-09-22
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多