繁体   English   中英

在nginx后面访问Flask应用时获取404

[英]Getting 404 when accessing Flask app behind nginx

我已经在nginx下配置了一个虚拟主机,因此:

server {
        listen          80;
        server-tokens   off;
        access_log      /var/log/nginx/api.example.com.access.log;
        error_log       /var/log/nginx/api.example.com.error.log;
        index           index.html index.htm;
        server_name     api.example.com;
        autoindex       on;

        location / {
                include         uwsgi_params;
                uwsgi_pass      unix:/var/www/api.example.com/xxx.sock;
        }
}

该文件位于sites-availablesites-enabled

我因此配置了uwsgi

[uwsgi]
chmod-socket = 666
socket = /var/www/api.example.com/xxx.sock
processes = 5
threads = 10
master = True
module = xxx 
callable = app 
chdir = /var/www/api.example.com
venv = /home/xxx/.virtualenvs/xxx
thunder-lock = True
uid = www-data
gid = www-data
plugins = http,python
vhost = True

我可以让uwsgi和nginx成功启动,但是当我访问http://api.example.com时,我总是得到nginx404。我认为它们都通过相同的套接字进行通信,因为与此相关的没有错误发生。 我还可以看到在/var/www/api.example.com//var/www/api.example.com/app下生成的.pyc文件,这些文件保存了我的视图和模型。

我该如何调试?

不确定,但是此nginx conf可能有效。 如果没有,请查看nginx和uwsgi日志。


server {
    listen      80;
    server_name api.xxxx.com;
    charset     utf-8;
    client_max_body_size 250M;

root /var/www/api.xxx.com/;
index index.html index.htm;

location / {
    try_files $uri $uri/ @proxy; 
}

location @proxy {
    include uwsgi_params;
    uwsgi_pass unix:/var/www/api.xxx.com/xxx.sock

    proxy_redirect     off;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
}

}

我发现了问题:Flask和uwsgi具有不同的应用程序名称。 当我回答时,它们的名称与上述名称相同,我忘记了重新启动服务器。

首先确保您的nginx具有HttpUwsgiModule,您可以通过运行命令“ nginx -V ”进行检查。 它将列出所有已配置的模块。

这是一个很好的链接http://wiki.nginx.org/HttpUwsgiModule

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM