Welcome! Log In Create A New Profile

Advanced

NGINX Reverse Proxy - ERR_TOO_MANY_REDIRECTS

Posted by DBCreator 
NGINX Reverse Proxy - ERR_TOO_MANY_REDIRECTS
April 30, 2021 11:04AM
Hello All!

Until now, I used a PHP script on the main server B 93.151.75.75, which was behind the NGINX reverse proxy server A 173.176.183.183. On the website2.com domain name. And it worked.
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 work correctly on the website2.com domain?
What am I doing wrong in server A 173.176.183.183 reverse proxy settings?

I am attaching below NGINX reverse proxy A 173.176.183.183 config and information from Redirect Checker.
I would be very grateful for advice!

nginx.conf (NGINX reverse proxy
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;
}
}
}

Redirect Checker:

Result
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

....................
Attachments:
open | download - Nginx Cloudflare.png (53.1 KB)
Re: NGINX Reverse Proxy - ERR_TOO_MANY_REDIRECTS
May 03, 2021 02:03AM
I needed to add this line to the common Nginx reverse proxy options -

proxy_set_header X-Forwarded-Proto $scheme;

and the problem was resolved.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 278
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready