如何解决CloudFlare + NGINX 反向代理,502 错误网关问题
我想使用 cloudflare + nginx 反向代理服务器,它将所有请求重定向到后端。
这是方案:
A: nginx 反向代理服务器
B:后端网络服务器
域:app1.com
CloudFlare > A(代理)> B(网络服务器)
不幸的是,我遇到了一些问题,当我转到 app1.com 域时,出现 CloudFlare 502 Bad Gateway 错误。
这是我的设置:
反向代理服务器,nginx conf :
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
upstream app1.com {
server BACKEND_IP:3030;
}
server {
server_name app1.com;
listen 443 ssl http2 ;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/ssl/certs/app1com.crt;
ssl_certificate_key /etc/ssl/private/app1com.key;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
location / {
proxy_pass http://app1.com;
}
}
Web 服务器后端,nginx conf :
server {
listen 127.0.0.1:3030;
root /home/backend/source/www;
index index.html index.htm index.nginx-debian.html index.php;
location / {
try_files $uri $uri/ @rules;
}
location @rules {
rewrite ^/(.*)$ /index.php?url=$1;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
if ($request_uri ~ \.php($|\?))
{
rewrite ^(.*)\.php$ $1 permanent;
}
include snippets/php_fastcgi.conf;
}
include snippets/general.conf;
}
感谢您的帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。