nginx + uwsgi + django 502 aws ec2 上的错误网关

nginx + uwsgi + django 502 aws ec2 上的错误网关

我已成功在 aws ec2 实例上安装了 nginx 和 uwsgi。但在访问公共 IP 时,它显示“502 错误网关”。尽管 nginx 和 uwsgi 服务器状态均为正在运行且处于活动状态。

uwsgi.ini 文件是:

[uwsgi]

project_name = server

base_dir = /home/ec2-user/virt_env

virtualenv = %(base_dir)

chdir = %(base_dir)/server/

module =  %(project_name).wsgi:application

master = true
processes = 4

# enable-threads  = true
# threads = 2

pidfile = django.uwsgi.pid

post-buffering = 204800

thunder-lock = True

uwsgi-socket = %(base_dir)/run/uwsgi.sock

chmod-socket = 666

socket-timeout = 300

reload-mercy = 8

reload-on-as = 512

harakiri = 50
max-requests = 5000

vacuum = true

disable-logging = True

logto = %(base_dir)/log/uwsgi.log

log-maxsize = 20971520

log-backupname = %(base_dir)/log/old-uwsgi.log

touch-reload = %(base_dir)/server/

# cpu-affinity = 1

max-worker-lifetime = 300

uwsgi.service文件是:

[Unit]
Description=uWSGI instance to serve updateMe project
After=network.target

[Service]
WorkingDirectory=/home/ec2-user/virt_env/server/
Environment="PATH=/home/ec2-user/virt_env/"
ExecStart=/home/ec2-user/virt_env/bin/uwsgi --ini /home/ec2-user/virt_env/server/conf/uwsgi.ini
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

nginx-uwsgi.conf文件是:

upstream django {
    server unix:/home/ec2-user/virt_env/run/uwsgi.sock;
}
server {
    listen 80;
    server_name 13.234.37.103;
    charset utf-8;
    client_max_body_size 128M;
    location /media {
        alias /home/ec2-user/virt_env/server/media;
    }
    location /static {
         alias /home/ec2-user/virt_env/server/static;
    }
    location / {
        include uwsgi_params;
        uwsgi_pass django
        uwsgi_read_timeout 300s;
        uwsgi_send_timeout 300s;
    }
    access_log /home/ec2-user/virt_env/log/dev-nginx-access.log;
    error_log /home/ec2-user/virt_env/log/dev-nginx-error.log;
}

日志文件中的错误是:

2019/04/23 05:51:07 [crit] 4338#0: *1 connect() to unix:/home/ec2-user/virt_env/run/uwsgi.sock 
failed (13: Permission denied) while connecting to upstream, 
client: 103.118.50.4, server: 13.234.37.103, request: "GET / HTTP/1.1", 
upstream: "uwsgi://unix:/home/ec2-user/virt_env/run/uwsgi.sock:", host: "13.234.37.103"

我还尝试了 chmod-socket 664、777,并将 sestatus (selinux) 更改为强制执行,重新启动了 psql、uwsgi、nginx 服务,但仍然显示 502 错误网关错误。

对于 selinux 我遵循这个答案

相关内容