我在偵聽埠 3000 的特定服務器(172.16.100.8)上生成了一個 OWASP Juice Shop docker 容器。
我在 172.16.100.26 上有一個 NGINX 反向代理,配置如下,但它導致 502 錯誤。
upstream juice_shop {
zone http_backend 64k;
server 172.16.100.8:3000;
}
server {
listen 80;
root /usr/share/nginx/html;
access_log /var/log/nginx/access.log combined;
location / {
proxy_pass http://juice_shop/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
有趣的是,當我直接訪問 172.16.100.8:3000 時,它成功地為我提供了網站。
我還嘗試在上游組指向本地主機的 172.16.100.8 本身上設定 NGINX。而這個作業得很好。
upstream juice_shop {
zone http_backend 64k;
server localhost:3000;
}
server {
listen 80;
root /usr/share/nginx/html;
access_log /var/log/nginx/access.log combined;
location / {
proxy_pass http://juice_shop;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
所以看來,問題只發生在我對另一臺服務器執行 proxy_pass 時。如果容器是在安裝 NGINX 的同一實體上生成的,則不會顯示。
感謝您的幫助。
uj5u.com熱心網友回復:
非常感謝您的指導。它有幫助!
我通過暫時禁用 SElinux 解決了這個問題。我的 NGINX 在 CENTOS 7 之上運行。
只是為了分享這個執行緒中的錯誤日志:
[root@nginx1 ~]# tail -f /var/log/nginx/error.log
...
2022/06/28 13:43:52 [crit] 4316#4316: *127 connect() to 172.16.100.8:3000 failed (13: Permission denied) while connecting to upstream, client: 2.2.2.2, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.16.100.8:3000/favicon.ico", host: "172.16.100.26", referrer: "http://172.16.100.26/"
[root@nginx1 ~]# sudo cat /var/log/audit/audit.log | grep nginx | grep denied | tail -3
type=AVC msg=audit(1656436366.765:4672009): avc: denied { name_connect } for pid=4316 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket permissive=0
type=AVC msg=audit(1656438232.386:4672026): avc: denied { name_connect } for pid=4316 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket permissive=0
type=AVC msg=audit(1656438232.453:4672027): avc: denied { name_connect } for pid=4316 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket permissive=0
[root@nginx1 ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
使用 sudo setenforce 0 臨時更改 SELinux 模式后
現在一切都好!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/498031.html
標籤:nginx nginx-反向代理
