运行uwsgi和nginx(centos)的python app出现502 Bad Gateway错误

时间:2017-07-26 17:11:04

标签: python nginx centos uwsgi wsgi

看到这个问题,但所有似乎都是Ubuntu,解决方案在Centos上对我不起作用。我有一个烧瓶应用试图从uwsgi运行并且正在

2017/07/26 17:44:24 [crit] 22785#0: *7 connect() to unix:/home/myname/perm_check/index.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/home/myname/perm_check/index.sock:", host: "127.0.0.1"

(根据这个https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-centos-7教程,它从virtualenv运行到localhost:500或localhost:8000和wsgi。

以下是我的文件: index.ini

[uwsgi]
module = wsgi

master = true
processes = 5

socket = index.sock
chmod-socket = 664
vacuum = true

die-on-term = true

index.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def check():
    return "<h1 style='color:red'>Test run...</h1>"


if __name__ == "__main__":
    app.run(host='0.0.0.0')

nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;


    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
    listen 80;
    server_name 127.0.0.1;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/myname/perm_check/index.sock;
        }
    }

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

我知道我在某处失去了一些简单的东西,但我不能为我的生活弄清楚。一切的权限是 myname:myname ,我正在尝试从127.0.0.1运行uwsgi服务。

1 个答案:

答案 0 :(得分:0)

解决了它,需要禁用SELinux并重启服务器