Nginx sets www access without www to change to www

Source: Internet
Author: User

Nginx sets www access without www to change to www

A recently developed Web project is deployed in an LNMP environment. In the past, nginx had only a point theory and was not actually used. The requirements for domain name resolution are as follows:

The user turned to access the http://www.cneotscn.com by entering the http://cneotscn.com and http://www.cneotscn.com. After querying nginx related documents and materials, we finally solved the problem.

The configuration file vhost/www. centoscn. conf (depending on your domain name configuration file) is edited as follows:

.....

......

Server
{

........

Server_namewww.cnotscn.com; // only one

......

}

Add the following code block at the bottom of the file (independent from the code above ):

Server {
Server_namecneotscn.com;
Rewrite ^ (. *) $ http://www.cneotscn.com $1 permanent;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.