Nginx Remove WWW And Respond To Both

前端 未结 6 1808
粉色の甜心
粉色の甜心 2020-12-29 21:53

I have the following nginx configuration fragment:

server {
   listen 80;

   server_name mydomain.io;

   root /srv/www/domains/mydomain.io;

   index index         


        
6条回答
  •  感情败类
    2020-12-29 22:39

    Another way to code it :

    if ($http_host ~* "^www\.(.+)$"){
        rewrite ^(.*)$ http://%1$request_uri redirect;
    }
    

    It works even with multiple domain names on the same code.

提交回复
热议问题