nginx转发请求时出现错误: 6009#0: *1 connect() to 127.0.0.1:9501 failed (13: Permission denied) while connecting to upstream
[root@localhost code]# vim + /var/log/nginx/error.log
2020/07/06 21:52:21 [error] 6009#0: *6 no live upstreams while connecting to upstream, client: 192.168.2.80, server: _, request: "GET /https/ HTTP/1.1", upstream: "https://www.baidu.com/", host: "192.168.2.140"
2020/07/06 21:52:29 [crit] 6009#0: *1 connect() to 127.0.0.1:9501 failed (13: Permission denied) while connecting to upstream, client: 192.168.2.80, server: _, request: "GET /report/ HTTP/1.1", upstream: "http://127.0.0.1:9501/report/", host: "192.168.2.140"
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location /https/ {
proxy_pass https://www.baidu.com/;
}
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /report/ {
proxy_pass http://127.0.0.1:9501/;
}
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
查了很多资料说是权限问题, 于是
vim /etc/nginx/nginx.conf
把其中的 user nginx; 改为 user root; 重启nginx不管用, 然后又改回去了
- 执行了下面一条命令, nginx都不需要重启, 就正常了, 可以正常访问 /https/ 的转发, 但是 /report/ 转发还是报错了
setsebool -P httpd_can_network_connect 1
2020/07/06 21:54:02 [error] 6009#0: *10 open() "/usr/share/nginx/html/home/msg/data/personalcontent" failed (2: No such file or directory), client: 192.168.2.80, server: _, request: "GET /home/msg/data/personalcontent?num=8&indextype=manht&_req_seqid=3114502296&asyn=1&t=1594086842083&sid=31906_1445_31325_32139_31254_32046_32230_31709_32258_26350 HTTP/1.1", host: "192.168.2.140", referrer: "http://192.168.2.140/https/"
把report的配置移动到https的转发配置后面重启nginx就好了