
[英]Nginx as reverse proxy for Apache (RHEL 8), http to https rewrites, ERR_TOO_MANY_REDIRECTS
[英]NGINX Reverse Proxy - ERR_TOO_MANY_REDIRECTS - how to fix?
到目前为止,我在主服务器 B 93.151.75.75 上使用了 PHP 脚本,该脚本在 NGINX 反向代理服务器 A 173.176.183.183 后面。 在网站上2.com域名。 它奏效了。 Now I have installed a new PHP script on the website2.com domain name and am crashing ((( If I set the HTTP protocol in the script settings, I get mixed content errors. If I turn on the HTTPS protocol, then I get an error - ERR_TOO_MANY_REDIRECTS. I tried placing this script on the website3.com domain name and it worked fine. Of course my main server B 93.151.75.75 has SSL certificates from Cloudflare on the website3.com domain name. How can I make this PHP script在 website2.com 域上正常工作?我在服务器 A 173.176.183.183 反向代理设置中做错了什么?
我在下面附上 NGINX 反向代理 A 173.176.183.183 配置和来自重定向检查器的信息。 我将非常感谢您的建议!
nginx.conf(NGINX反向代理173.176.183.183)
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_header_timeout 5s;
client_body_timeout 5s;
send_timeout 10s;
reset_timedout_connection on;
client_header_buffer_size 2k;
client_body_buffer_size 20k;
large_client_header_buffers 4 8k;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
# include /etc/nginx/conf.d/*.conf;
#proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=static_cache:8m inactive=10m max_size=1024M;
#proxy_cache_min_uses 1;
server {
listen 80;
server_name website2.com www.website2.com;
access_log /var/log/nginx/website2.com-access.log;
error_log /var/log/nginx/website2.com-error.log;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/ssl/www.website2.com.pem;
ssl_certificate_key /etc/ssl/www.website2.com.key;
server_name website2.com;
access_log /var/log/nginx/website2.com-ssl-access.log;
error_log /var/log/nginx/website2.com-ssl-error.log;
client_max_body_size 100m;
location / {
proxy_pass http://93.151.75.75;
proxy_set_header Host $host;
proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
#proxy_request_buffering off;
#proxy_cache static_cache;
}
}
}
重定向检查器:
https://website2.com/
302 Found
https://website2.com
302 Found
https://website2.com
302 Found
https://website2.com
302 Found
https://website2.com
302 Found
https://website2.com
302 Found
https://website2.com
302 Found
https://website2.com
.........
>>> https://website2.com/
> --------------------------------------------
> 302 Found
> --------------------------------------------
Status: 302 Found
Code: 302
Server: nginx/1.16.1
Date: Fri, 30 Apr 2021 14:05:18 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: PHP/7.3.24
Location: https://website2.com
Set-Cookie: PHPSESSID=016eaf866d782aad092458f7ecf65f9c; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
>>> https://website2.com
> --------------------------------------------
> 302 Found
> --------------------------------------------
Status: 302 Found
Code: 302
Server: nginx/1.16.1
Date: Fri, 30 Apr 2021 14:05:18 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: PHP/7.3.24
Location: https://website2.com
Set-Cookie: PHPSESSID=f5bb7fb2f39189d662f3357ff61927f3; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
>>> https://website2.com
> --------------------------------------------
> 302 Found
> --------------------------------------------
Status: 302 Found
Code: 302
Server: nginx/1.16.1
Date: Fri, 30 Apr 2021 14:05:18 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: PHP/7.3.24
Location: https://website2.com
Set-Cookie: PHPSESSID=c0cb7b8a0e23d2726f3c0f8070192b04; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
....................
我需要将此行添加到常见的 Nginx 反向代理选项 -
proxy_set_header X-Forwarded-Proto $scheme;
问题就解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.