Nginx automatically jump to the www domain with configuration rules, Nginx jump to the main domain of multi-domain

Jump Jump Nginx nginx domain name to www domain name automatically rule configuration, if you set the xxx.org domain name automatically jump to www.xxx.org when the user accesses it?


First, the definition of inside your domain management xxx.org and www.xxx.org point to your host ip address, you can use the nslookup command to test

Direct input and nslookup www.xxx.org nslookup xxx.org both ip A record can be directed.

image.png


Second, the configuration in which nginx rewrite rules. Open Nginx.conf find server configuration file section: [The following is my server configuration section]

############# prohibited IP addresses to access ########### 
    Server { 
      the listen the default_server 80; 
      server_name _; 
      return 403; 
    } 
######### #### prohibited IP addresses to access ########### 


    Server { 
      the listen 80; 
      # listen443 SSL; 
      #return 500; 
      server_name www.xxx.org xxx.org; 
      IF ($ Host = 'WWW! .xxx.org ') { 
      the rewrite ^ / (*) $ http://www.xxx.org/$1 Permanent;. 
      } 
   }

Such is the user direct access xxx.com direct jump www.xxx.com. That let the domain name without the www domain name to jump to the www.


Third, expand

May be more than two domain names, three domain names are free to jump, or have they all jump to xxx.xxx.com this domain, you can add the following statement

    server {
      listen       80;
         #listen443 ssl;
         #return 500;
      server_name  xxx.xxx.com xxx.xxx.org;
         if ($host != 'xxx.xxx.org') {
         rewrite ^/(.*)$ http://xxx.xxx.com/$1 permanent;
         }
     }

The above may make another jump to the second-level domain xxx.xxx.org xxx.xxx.com

So as not to give up after two domain names, the impact on the search engine. Helpful for seo


Guess you like

Origin blog.51cto.com/meiling/2441529