I recently created a lightsail NGINX instance on AWS.
I opened my server block file and added the below code:
server {
listen 80;
server_name www.example.com
return 301 https://example.com
}
When I run
curl -I example.com
It returns the correct response saying it is redirecting to the non www url.
My instance DNS resolves to a vp6 address because I have load balancers enabled. The load balancers automatically redirect from http to https.
I have an A record which point to the server ip.
Also, tried an a record which points to the load balancers.
With either record it says failed to load to many redirects.
Any idea what could be causing this?
When I try to access the original config file created by AWS for the load balancers, there are just tons of @@@@@@ in the file. So all my server blocks are in another file.
The block you’ve posted is fine, so the problem is in some the configuration you have not posted. Which makes it impossible to see where the issue lies.
Could you post the other configurations as well please?
server {
# Port to listen on, can also be set in IP:PORT format
listen 443 ssl;
ssl_certificate bitnami/certs/server.crt;
ssl_certificate_key bitnami/certs/server.key;
include "/opt/bitnami/nginx/conf/bitnami/*.conf";
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
When I add this to the same file, underneath the above server block., the server doesn’t pass health check.
I tried the suggestion and every other possible alternative.
It works initially but then the server says health check failed, and in the browser, while it redirects to the correct URL, it then says too many redirects which then disables the server and the second server takes over.
I have a feeling that there is some file that I can’t find which has already defined a redirect rule so when I apply the redirect rule in the server config file above, it then just says too many redirects. I’ve searched the net to where the location is but the only doc articles that can be found are for Apache.