Because I bought W2's VPS a few days ago, and I was still looking for the other party to solve some problems, I installed the LNMP environment without putting anything in it. I have nothing to do today, so I will temporarily put a picture of a beautiful woman on it. After releasing it, I found that I set www.01mm.net through the virtual host domain name established by ./vhost.sh. When I opened 01mm.net without www, it turned out to be the page of LNMP home directory.
How to make 01mm.net automatically redirect to www.01mm.net? This is the problem with 301 redirect .
First open the /usr/local/nginx/conf/vhost/www.01mm.net.conf file. The original code is as follows:

server
    {
        listen   <x2 >   80;
        server_name www.01mm.net;
  < x2>     index index.html index.htm index.php default.html default.htm default.php;
    < x2>   root  /home/wwwroot/www.01mm.net;
        include other. conf;
        location ~ .*.(php|php5)?$
             {
       < x2>        fastcgi_pass  unix:/tmp/php-cgi.sock;
                 fastcgi_index index.php;
                 include fcgi.conf;
             }
     < x2>  location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
       <x2 >    {
                 expires      30d;
      <x2 >     }
        location ~ .*.(js|css)?$
            {
   < x2>            expires    <x2 > 12h;
            }
  < x2>     access_log off;
    }

I added the following code at the end of this code:

server {
server_name 01mm.net;
rewrite ^(.*) http://www.01mm.net$1 permanent;
}

Please note that if there are two addresses after the original code server_name, including the address without www, please delete them first!
In addition, after the modification is completed, please restart LNMP.

/root/lnmp stop
/root/lnmp start

At this point, 301 redirect is completed. Now you can automatically redirect to www without entering the www address. Let’s take a picture from the beauty picture site:
301


Hong Kong/United States/Domestic High Speed ​​VPS

postid
21848

Leave a Reply