I have successfully installed nginx and uwsgi on aws ec2 instance. But on hitting the public IP its showing "502 bad gateway". Though both nginx and uwsgi server status is running and active.
The uwsgi.ini file is :
[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
The uwsgi.service file is:
[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
The nginx-uwsgi.conf file is:
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;
}
The errors in the log file are:
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"
Also I have tried chmod-socket 664, 777 and changed sestatus (selinux) to enforcing, restarted psql, uwsgi, nginx services still it is showing 502 bad gateway error.
For selinux I followed this answer.