nginx调试了各种姿势,始终页面展示502,查看了访问日志
tail -f /var/log/nginx/error.log
2023/01/18 14:27:21 [crit] 7992#7992: *24 connect() to 127.0.0.1:8000 failed (13: Permission denied) while connecting to upstream, client: 192.168.50.104, server: , request: "GET /admin/sale/purchaseorder/ HTTP/1.1", upstream: "http://127.0.0.1:8000/admin/sale/purchaseorder/", host: "192.168.50.178:81"
2023/01/18 14:27:21 [crit] 7992#7992: *24 connect() to [::1]:8000 failed (13: Permission denied) while connecting to upstream, client: 192.168.50.104, server: , request: "GET /admin/sale/purchaseorder/ HTTP/1.1", upstream: "http://[::1]:8000/admin/sale/purchaseorder/", host: "192.168.50.178:81"
2023/01/18 14:27:21 [error] 7992#7992: *24 no live upstreams while connecting to upstream, client: 192.168.50.104, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://backend/favicon.ico", host: "192.168.50.178:81", referrer: "http://192.168.50.178:81/admin/sale/purchaseorder/"
原来是被拒绝了,可以看到nginx接收到了请求。
发现自己只开放了这几个端口,少了8000
端口
# semanage port --list
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
增加端口,发现端口已经被占用了那就改nginx
配置端口和gunicorn
的服务端口为9000
吧
# semanage port --add --type http_port_t --proto tcp 8000
[root@localhost xl]# semanage port --add --type http_port_t --proto tcp 8000
ValueError: Port tcp/8000 already defined
nginx配置文件修改,并重启服务service nginx restart
# xl_nginx.conf
upstream channels-backend {
server localhost:9000;
}
server {
listen 80;
server_name 192.168.50.178;
charset utf-8;
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_pass http://channels-backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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;
}
# Django media
location /media {
alias /opt/xl/media; # your Django project's media files - amend as required
}
location /static {
alias /opt/xl/static; # your Django project's static files - amend as required
}
}
重启gunicorn服务,搞定
gunicorn xl.asgi:application -w 2 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:9000 --log-file -
网友评论