web.py + uwsgi + nginx 未找到应用

1 投票
1 回答
6388 浏览
提问于 2025-04-18 11:05

我正在尝试部署 nginx、uwsgi 和 web.py。

这是我在 /www/python/testme/ 目录下的 index.py 文件:

import web

urls = (
  '/', 'index'
)

app = web.application(urls, globals())

class index:
        def GET(self):
                return "Hello, world!"

if __name__ == "__main__": app.run()

application = app.wsgifunc

这是我为 Python 配置的 nginx 和 uwsgi:

/etc/nginx/sites-available/python
    server {
            listen          8080;
            server_name     $hostname;
            access_log /www/python/testme/logs/access.log;
            error_log /www/python/testme/logs/error.log;

            location / {
                #uwsgi_pass      127.0.0.1:9001;
                uwsgi_pass      unix:///tmp/test.socket;
                include         uwsgi_params;
                uwsgi_param     UWSGI_SCHEME $scheme;
                uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
            }


    }

这是我在 /etc/uwsgi/app-available/testme.ini 中的 uwsgi 配置文件:

[uwsgi]
gid = www-data
uid = www-data
logdate = true
logto = /var/log/uwsgi/testme.log
socket = /tmp/test.socket
#socket = 127.0.0.1:3031
master = true
plugins = python

我的 uwsgi 服务运行正常,nginx 也在按预期监听 8080 端口。

但是,当我从浏览器访问我的域名时,出现了错误日志:/var/log/uwsgi/testme.log

ImportError: No module named index
Wed Jun 25 19:14:54 2014 - unable to load app 0 (mountpoint='') (callable not found or import error)
Wed Jun 25 19:14:54 2014 - --- no python application found, check your startup logs for errors ---
[pid: 32604|app: -1|req: -1/5] 46.197.209.106 () {48 vars in 919 bytes} [Wed Jun 25 19:14:54 2014] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)
ImportError: No module named index
Wed Jun 25 19:14:54 2014 - unable to load app 0 (mountpoint='') (callable not found or import error)
Wed Jun 25 19:14:54 2014 - --- no python application found, check your startup logs for errors ---
[pid: 32604|app: -1|req: -1/6] 46.197.209.106 () {46 vars in 839 bytes} [Wed Jun 25 19:14:54 2014] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)

1 个回答

3

至少,这里是错误的——你指定了两个不同的套接字。

你的uwsgi配置:

socket = /tmp/testme.socket

你的nginx配置:

uwsgi_pass      unix:///tmp/test.socket

撰写回答