0

I am getting a redirect error im not sure how to fix. The error is; ERR_TOO_MANY_REDIRECTS

Heres my host file on nginx. Any advice appreciated. Thanks.

# HTTP
server {
 server_name _;
 # I added the line below to solver: Could not automatically find a matching server block for mail.mydomain.net. Set the `server_name` directive to use the Nginx installer.
 server_name mydomain.net www.mydomain.net;
 # Redirect all insecure http:// requests to https://
 return 301 https://$host$request_uri;
 listen [::]:443 ssl ipv6only=on; # managed by Certbot
 listen 443 ssl; # managed by Certbot
 ssl_certificate /etc/letsencrypt/live/mydomain.net/fullchain.pem; # managed by Certbot
 ssl_certificate_key /etc/letsencrypt/live/mydomain.net/privkey.pem; # managed by Certbot
 include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
 ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
 if ($host = www.mydomain.net) {
 return 301 https://$host$request_uri;
 } # managed by Certbot
 if ($host = mydomain.net) {
 return 301 https://$host$request_uri;
 } # managed by Certbot
 listen 80;
 listen [::]:80;
 server_name _;
 server_name mydomain.net www.mydomain.net;
 return 404; # managed by Certbot
}

I have tried without the host_name as it previously was but that doesnt work. Im not sure what to try now as I am more used to apache and nginx seems quite different.

asked May 10, 2024 at 10:05

1 Answer 1

1

Your lines of

 listen [::]:443 ssl ipv6only=on; # managed by Certbot
 listen 443 ssl; # managed by Certbot

are not HTTP, therefore you will need to remove the

 # Redirect all insecure http:// requests to https://
 return 301 https://$host$request_uri;

lines just before that and test again (don't forget to deploy your changes to sites-enabled or where you need it to be enabled and to restart nginx). That might already fix your issue, but you will also need to test this so, if you still have these redirects, some of them may come from the app code.

answered May 10, 2024 at 10:33
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.