NGINX ERR_TOO_MANY_REDIRECTS after installing SSL
That error usually means that you have round redirect somewhere in your config - a redirect to itself for example admin -> admin will produce endless loop so your browser senses that and gives error.
I'd start by simplifying that nginx config a bit. For example you have
server {
listen 80;
server_name url.com;
return 301 https://www.url.com$request_uri;
}
server {
set $MAGE_ROOT /var/www/html/url.com/www.url.com;
listen 80;
#server_name url.hammer-loesungen.de;
server_name www.url.com;
return 301 https://www.url.com$request_uri;
}
Can be set as:
server {
listen 80;
server_name url.com www.url.com;
return 301 https://www.url.com$request_uri;
}
I personally use the following:
server {
listen 80;
server_name url.com www.url.com;
## Redirect to HTTPs
location / {
return 301 https://$host$request_uri; # enforce https
}
}
Go trough the config and remove anything that you don't need, merge duplicate things in the same rules for simplicity. If after that there is still a round redirect try to debug with curl:
curl -kvv http://url.com/admin
curl -kvv https://url.com/admin
And so on for all the subdomains.
Related videos on Youtube
Chris
Updated on September 18, 2022Comments
-
Chris over 1 year
It seems, the whole website (Magento 2 shop) is working well but the backend isn't. The backend is located under:
url.com/admin
The rest of the shop with url.com and all categoriesurl.com/cat1/subcat1
is working just fine.In my browser (chromium) I get a: ERR_TOO_MANY_REDIRECTS
Nothing in NGINX error log, and 7 times a 302 in access log:
"GET /admin/admin/index/index/key/1d0cb4d5cebce23da3792027d3ec6f54/ HTTP/1.1" 302
admin and index are twice there - not sure whether that would be an indicator?
That's my nginx conf for that vhost (mostly the official one + 80 to 443 forwarding + some blocking for bots):
server { listen 80; server_name url.com www.url.com; location / { return 301 https://www.url.com$request_uri; # enforce https } } server { set $MAGE_ROOT /var/www/html/url.com/www.url.com; listen 443 ssl; ssl on; ssl_certificate /home/secuuser/ssl_certificate/url.com.bundle.crt; ssl_certificate_key /home/secuuser/ssl_certificate/url.com.priv.key; server_name www.url.com; access_log /var/log/nginx/url.com_access.log; error_log /var/log/nginx/url.com_error.log; root $MAGE_ROOT/pub; index index.php; autoindex off; charset UTF-8; error_page 404 403 = /errors/404.php; #add_header "X-UA-Compatible" "IE=Edge"; location / { try_files $uri $uri/ /index.php?$args; } # PHP entry point for main application location ~ (index|get|static|report|404|503)\.php$ { try_files $uri =404; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_buffers 1024 4k; fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off"; fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=18000"; fastcgi_read_timeout 600s; fastcgi_connect_timeout 600s; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } gzip on; gzip_disable "msie6"; gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 16 8k; gzip_proxied any; gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss image/svg+xml; gzip_vary on; }
I've seen plenty of similar issues here and online in general and tried some. But I haven't been able to transfer the gained knowledge into a solution for my case.
-
Cristian Matthias Ambæk about 6 yearsIs this a single sites-available configuration?
-
Tero Kilkanen about 6 yearsThe problem is most likely not in nginx configuration, since you are receiving a
302
redirect and nothing in your nginx configuration generates302
redirects, they are all301
redirect.
-
-
Chris about 6 yearsI've condensed the config down to a barebone. What would I look for in the curl output? There is
HTTP/1.1 302 Found
but I already suspected sth similar. -
Daniel about 6 yearsLook for the 301 Moved Permanently and take special look at the Location: header. It should be url.com/location. Then do a curl to this new location, it should return 200/204 and actual page. If it returns 302 take a look at your rewrite rules(the ones starting with rewrite not the return ones), those are probably messing up. Try to disable them one by one until you hit the one causing this and post it here to see.
-
Chris about 6 yearsIt seems to have been a setting in Magento DB. There are 2 URLs to be configured secure and insecure. It seems the insecure and my rewrite played tennis here.