Nginx Domain Name Configuration method

Source: Internet
Author: User

nginx binding multiple domain names can be a number of domain rules to write a configuration file, you can also set up a plurality of domain name configuration files, I generally for management convenience, each domain name to build a file, some of the same domain name can also be written in a general configuration file.

one, each domain name a file of the wording
First Opennginx Domain name configuration file storage directory:/usr/local/nginx/conf/servers,To bind the domain name www.myserver.com, create a file in this directory: www.myserver.com.conf then write the rules in this file, such as:
Server
{
Listen 80;
server_name www.myserver.com; #绑定域名
Index index.htm index.htmlindex.php; #默认文件
root/home/www/myserver.com; #网站根目录
includelocation.conf; #调用其他规则, can also be removed
}
Then re-start the Nginx server, the domain name is bound successfully
Nginx Server Restart command:/etc/init.d/nginx restart

second file multiple domain name notation
A file to add more than one domain name rule is the same, as long as the above a single domain name repeatedly written down is OK, such as:
Server
{
Listen 80;
server_name www.myserver.com; #绑定域名
Index index.htm index.htmlindex.php; #默认文件
root/home/www/myserver.com; #网站根目录
includelocation.conf; #调用其他规则, can also be removed
}

Server
{
Listen 80;
server_name msn.myserver.com; #绑定域名
Index index.htm index.htmlindex.php; #默认文件
root/home/www/msn.myserver.com; #网站根目录
includelocation.conf; #调用其他规则, can also be removed
}


third, not with the WWW domain name plus 301 Jump
If the domain name without the www to add 301 jump, it is also bound to the same domain name, the first binding without the WWW domain name, just do not write the site directory, but do 301 jump, such as:

Server
{
Listen 80;
server_name myserver.com;
Rewrite ^/(. *) http://www.myserver.com/$1 permanent;
}

iv. add 404 pages
Add 404 pages that can be added directly inside, such as:

Server
{
Listen 80;
server_name www.myserver.com; #绑定域名
Index index.htm index.htmlindex.php; #默认文件
root/home/www/myserver.com; #网站根目录
includelocation.conf; #调用其他规则, can also be removed
Error_page 404/404.html;
}

Finally, there is a way to note that there may be a need to prohibit IP direct access to port 80 or prohibit the non-site domain name binding our IP, so that should
To do this, put it on top of the previous server:

server{
Listen default;
server_name _;
return 403;
}


This article is from the "Cool bit Linux" blog, so be sure to keep this source http://coolbyte.blog.51cto.com/8289854/1688464

Nginx Domain Name configuration method

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.