This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13897|Reply: 0

[Web] Nginx domain name access judgment

[Copy link]
Posted on 12/7/2015 7:24:30 PM | | |
The requirements are as follows:

1. Access to non-www.abc.com domain names, return 403 to prevent malicious parsing.

Even if someone else's domain is bound to your host's IP, they won't be able to access your site, and if a user accesses his domain name, the user's browser will return a 403 error instead of jumping out of your site.
2. When the abc.com domain name is accessed, the automatic 301 is rewritten to www.abc.com, increasing the SEO weight...

Increase domain authority
Optimization of web page inclusion
It is conducive to the delivery of web page PR
It can promote search engine optimization results
Be friendly to user experience
3. The above two needs coexist.



1. Access to non-www.abc.com domain names, return 403 to prevent malicious parsing.

server {
        listen       80;
        server_name  abc.com   www.abc.com;
                if ( $host != 'www.abc.com' ){  
        return 403;
        }
2. When a abc.com domain name is accessed, the 301 is automatically rewritten to www.abc.com.

server {
        listen       80;
        server_name  abc.com   www.abc.com;
                if ( $host = 'abc.com' ){                 
        rewrite http://abc.com/(.*) http://www.abc.com/$1 permanent;
        }
3. Non-www.abc.com domain name access, return 403 error, when abc.com domain name access, automatically rewrite 301 to www.abc.com.

server {
        listen       80;
        server_name  www.abc.com abc.com;
               
                if ( $host = 'abc.com' ){  
        rewrite http://abc.com/(.*) http://www.abc.com/$1 permanent;
      }
          
                if ( $host != 'www.abc.com' ){  
        return 403;
        #rewrite ^/(.*)$ http://www.abc.com/$1 permanent;               

      }





Previous:console automatically refreshes the current page
Next:The 12306 strange verification code was cracked, and it couldn't stop scalpers at all
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com