0

I want to redirect all domain from www to non-www using Nginx config file nginx.conf. I have tried using the below configuration but it only work for URL start with HTTP but does not work for HTTPS

I have added below server block

server {
    server_name "~^(?!www\.).*" ;
    return 301 $scheme://$1$request_uri ;
}
Krunal
  • 101
  • Does this answer your question? [Nginx HTTPS www to non-www redirect issue](https://serverfault.com/questions/634415/nginx-https-www-to-non-www-redirect-issue) and [nginx https www redirect to non-www using let's encrypt certbot](https://serverfault.com/questions/891931/nginx-https-www-redirect-to-non-www-using-lets-encrypt-certbot?rq=1) – djdomi Jun 14 '22 at 06:50
  • @djdomi No, It's the domain-specific configuration I need a global solution for all domains. – Krunal Jun 14 '22 at 07:31
  • IMHO your configuration missing the listen directive. – djdomi Jun 14 '22 at 12:22
  • I have added but it's not working – Krunal Jun 14 '22 at 14:50
  • Global solution is impossible due to the reasons I [described](https://stackoverflow.com/a/72616883/7121513) on [so]. – Ivan Shatsky Jun 14 '22 at 16:13

0 Answers0