如果配置好nginx和uwsgi后,依然访问失败
!!!注意:前端build文件最好放到/var/目录下,/root/目录下一直报没有权限执行index.html
- 查看服务状态
sudo systemctl status your.service
- 查看uwsgi日志,目录为uwsgi文件中配置的路径,如:
logto=/home/datauser/log/uwsgi/backend.log
- 查看nginx错误日志,目录为nginx.conf文件中配置的路径,如:
/var/log/nginx
- 如果想单独调试uwsgi+django,注意uwsgi配置
socket=127.0.0.1:8005
,socket改为http
以下为遇到的问题:
a. nginx Failed to read PID from file /run/nginx.pid: Invalid argument
解决方法:mkdir -p /etc/systemd/system/nginx.service.d
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
systemctl daemon-reload
systemctl restart nginx.service
b. invalid request block size: 21327 (max 4096)...skip
解决方法:uwsgi配置文件中添加一行 buffer-size=32768
c. selinux导致错误 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream
解决方法,命令行执行 setsebool -P httpd_can_network_connect 1
d. nginx的权限问题(13: Permission denied)解决办法
修改nginx.conf文件:user nginx 改成 user root
停止nginx -s stop
重启nginx -c nginx.conf
注意:不要使用systemctl 或 service方式启动,selinux权限不让nginx访问nginx.conf
其它,如:宿主机访问不了虚拟机系统的8080端口:
- 开放端口号
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload