Welcome! Log In Create A New Profile

Advanced

www to non-www redirection gives me 400 bad request error

Posted by nginxproblem5 
www to non-www redirection gives me 400 bad request error
August 14, 2024 08:12PM
I'm trying to redirect all www to non-www domain address. I have installed my LetsEncrypt SSL for non-www domain. non-www domains are working fine. I have configured www to non-www redirection on my Nginx running on Ubuntu server. I have encountered a strange problem.

On Windows Firefox and Mac Safari browser, http://www.examplesite.com will redirect to https://www.examplesite.com and it says it's a suspicious domain and I need to add exception to proceed. It looks like these two browsers are looking for SSL certificate for www.examplesite.com instead of examplesite.com

When I click on add exception and access https://www.examplesite.com, I get 400 bad request page from Nginx.

This problem doesn't happen on Chrome, Opera, Edge browsers. Only the two browsers get the redirection bug. What should I do to fix the bug on Safari and Windows Firefox? The domain is from Godaddy. It looks like Android Firefox and Chrome browsers don't experience this bug either.

Here are my Nginx configs:

/etc/nginx/conf.d/redirect.conf

server {

server_name www.examplesite.com;

rewrite ^/(.*)$ https://examplesite.com/$1 permanent;

}

/etc/nginx/sites-available/examplesite

server {

server_name xxx.xx.xxx.xxx examplesite.com www.examplesite.com;

location = /favicon.ico { access_log off; log_not_found off; }

location /static/ {

root /home/ubuntu/examplesite;

}

location / {

include proxy_params;

proxy_pass http://unix:/run/gunicorn.sock;

}

listen 443 ssl; # managed by Certbot

ssl_certificate /etc/letsencrypt/live/examplesite.com/fullchain.pem; # man>

ssl_certificate_key /etc/letsencrypt/live/examplesite.com/privkey.pem; # m>

include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {

if ($host = examplesite.com) {

return 301 https://$host$request_uri;

} # managed by Certbot

if ($host = www.examplesite.com) {

return 301 https://examplesite.com$request_uri;

}

listen 80;

server_name xxx.xx.xxx.xxx examplesite.com www.examplesite.com;

return 404; # managed by Certbot

}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 93
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready