Django Nginx和gunicorn工作正常,但站点无法连接。我怎样才能解决这个问题?
我的英语不好。我希望你能理解 我想使用AWSEC2部署django项目。 (实例设置:Ubuntu服务器18.04 LTS…,t2 micro)+RDS+Gunicorn+Nginx 我完成了ec2的所有设置。 Python manage.py运行服务器0.0.0.0:8000工作正常 gunicorn——绑定0.0.0.0:8000后端。wsgi:应用程序也可以正常工作 但是当sudo systemctl gunicorn启动时,当我连接到http://{mypublic IPv4}时,该站点无法连接 我的/etc/systemd/system/gunicorn.serviceDjango Nginx和gunicorn工作正常,但站点无法连接。我怎样才能解决这个问题?,django,amazon-web-services,nginx,gunicorn,Django,Amazon Web Services,Nginx,Gunicorn,我的英语不好。我希望你能理解 我想使用AWSEC2部署django项目。 (实例设置:Ubuntu服务器18.04 LTS…,t2 micro)+RDS+Gunicorn+Nginx 我完成了ec2的所有设置。 Python manage.py运行服务器0.0.0.0:8000工作正常 gunicorn——绑定0.0.0.0:8000后端。wsgi:应用程序也可以正常工作 但是当sudo systemctl gunicorn启动时,当我连接到http://{mypublic IPv4}时,该站点
(venv) ubuntu@ip-172-31-32-142:~/diary-with-pet/Backend$ cat /etc/systemd/system/gunicorn.service
当我开始gunicorn的时候
(venv) ubuntu@ip-172-31-32-142:~/diary-with-pet/Backend$ sudo systemctl start gunicorn
(venv) ubuntu@ip-172-31-32-142:~/diary-with-pet/Backend$ sudo systemctl enable gunicorn
(venv) ubuntu@ip-172-31-32-142:~/diary-with-pet/Backend$ sudo systemctl status gunicorn
- nginx也很好
- my/etc/nginx/可用站点/后端
$ sudo ln -s /etc/nginx/sites-available/Backend /etc/nginx/sites-enabled
我该如何解决这个问题?似乎一切都正常运行。您是否检查了EC2的安全组规则?您需要允许端口80上的入站流量。出于测试目的,请编辑安全组规则并从
My IP
添加HTTP,以仅允许从您的计算机进行访问。如果您希望向世界公开您的EC2,请将My IP
更改为Anywhere
。这是您的情况吗?我允许在EC2安全组中使用端口80,而不考虑位置。但是,结果没有改变。当连接到EC2时,能否curl localhost:80
?你得到答复了吗?很抱歉看到你迟到了。我得到了这个响应502坏网关502坏网关
nginx/1.14.0(Ubuntu)
,所以它不是AWS中的东西,而是应用程序中的东西。也许是本地主机:8000?我不确定您在EC2中本地公开了哪个端口
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset:
Active: active (running) since Mon 2021-04-19 05:15:22 UTC; 1 day 5h ago
Main PID: 9679 (gunicorn)
Tasks: 4 (limit: 1140)
CGroup: /system.slice/gunicorn.service
├─9679 /home/ubuntu/diary-with-pet/Backend/venv/bin/python3 /home/ubu
├─9700 /home/ubuntu/diary-with-pet/Backend/venv/bin/python3 /home/ubu
├─9702 /home/ubuntu/diary-with-pet/Backend/venv/bin/python3 /home/ubu
└─9703 /home/ubuntu/diary-with-pet/Backend/venv/bin/python3 /home/ubu
Apr 19 05:15:22 ip-172-31-32-142 systemd[1]: Started gunicorn daemon.
Apr 19 05:15:22 ip-172-31-32-142 gunicorn[9679]: [2021-04-19 05:15:22 +0000] [96
Apr 19 05:15:22 ip-172-31-32-142 gunicorn[9679]: [2021-04-19 05:15:22 +0000] [96
Apr 19 05:15:22 ip-172-31-32-142 gunicorn[9679]: [2021-04-19 05:15:22 +0000] [96
Apr 19 05:15:22 ip-172-31-32-142 gunicorn[9679]: [2021-04-19 05:15:22 +0000] [97
Apr 19 05:15:22 ip-172-31-32-142 gunicorn[9679]: [2021-04-19 05:15:22 +0000] [97
Apr 19 05:15:23 ip-172-31-32-142 gunicorn[9679]: [2021-04-19 05:15:23 +0000] [97
lines 1-18/18 (END)
(venv) ubuntu@ip-172-31-32-142:~/diary-with-pet/Backend$ sudo rm -f /etc/nginx/sites-enabled/default
(venv) ubuntu@ip-172-31-32-142:~/diary-with-pet/Backend$ sudo rm -f /etc/nginx/sites-available/default
(venv) ubuntu@ip-172-31-32-142:~/diary-with-pet/Backend$ sudo service nginx restart
(venv) ubuntu@ip-172-31-32-142:~/diary-with-pet/Backend$ sudo service nginx status
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Active: active (running) since Tue 2021-04-20 10:41:41 UTC; 6s ago
Docs: man:nginx(8)
Process: 19581 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5
Process: 19596 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (cod
Process: 19584 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 19597 (nginx)
Tasks: 2 (limit: 1140)
CGroup: /system.slice/nginx.service
├─19597 nginx: master process /usr/sbin/nginx -g daemon on; master_pr
└─19598 nginx: worker process
Apr 20 10:41:41 ip-172-31-32-142 systemd[1]: Stopped A high performance web serv
Apr 20 10:41:41 ip-172-31-32-142 systemd[1]: Starting A high performance web ser
Apr 20 10:41:41 ip-172-31-32-142 systemd[1]: nginx.service: Failed to parse PID
Apr 20 10:41:41 ip-172-31-32-142 systemd[1]: Started A high performance web serv
server {
listen 80;
server_name 15.164.212.81;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/diary-with-pet/Backend;
}
location /media/ {
root /home/ubuntu/diary-with-pet/Backend;
}
location / {
include proxy_params;
proxy_pass http://15.164.212.81:8000;
}
}
server {
listen 80;
server_name {my public IPv4};
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/diary-with-pet/Backend;
}
location /media/ {
root /home/ubuntu/diary-with-pet/Backend;
}
location / {
include proxy_params;
proxy_pass http://{public IPv4}:8000;
}
}
$ sudo ln -s /etc/nginx/sites-available/Backend /etc/nginx/sites-enabled