Multiple Domain Names are bound to Nginx on the CentOS server.
When you bind multiple domain names to nginx, you can write multiple domain name rules into one configuration file. You can also create multiple domain name configuration files for ease of management, each domain name creates a file, and some similar domain names can also be written in a general configuration file.
1. One file for each domain name
First open the nginx domain name configuration file storage directory:/usr/local/nginx/conf/servers, to bind the domain name www.your-domain.com, create a file in this directory: www. the your-domain.conf then writes rules in this file, such as: server1234567{
listen
80
;
server_name
Www.your-domain.com; # Bind a domain name
Index index.htm index.html index. php; # default file
Root/home/www/your-domain.com; # website root directory
Include location. conf; # Call other rules, which can also be removed
}
Then restart the nginx server, and the domain name is successfully bound to the nginx server. restart the command:/etc/init. d/nginx restart
2. Writing multiple domain names in one file
The same applies to rules for adding multiple domain names to a file. You only need to write down the previous single domain name repeatedly, for example, server.
1234567891011121314
{
listen
80
;
Server_name bbs.your-domain.com; # bind a domain
Index index.htm index.html index. php; # default file
Root/home/www/bbs.your-domain.com; # bbs directory
Include location. conf; # Call other rules, which can also be removed
}server
{
listen
80
;
Server_name www.your-domain.com; # bind a domain
Index index.htm index.html index. php; # default file
Root/home/www/www.your-domain.com; # website root directory
Include location. conf; # Call other rules, which can also be removed
}
3. Add 301 redirection for domain names without www
If you want to add a 301 jump to a domain name without www, it is the same as binding a domain name. First, bind a domain name without www. Instead of writing a website directory, you can perform a 301 jump, for example:
123456
server
{
listen
80
;
server_name your-domain.com;
rewrite ^/(.*) http:
// Www.your-domain.com/#1 permanent;
}
4. Add 404 web pages
To add 404 web pages, you can add them directly in the page, for example:
123456789
server
{
listen
80
;
Server_name www.your-domain.com; # bind a domain
Index index.htm index.html index. php; # default file
Root/home/www/your-domain.com; # website root directory
Include location. conf; # Call other rules, which can also be removed
error_page
404
/
404
.html;
}
After learning the above four rules and methods, you can solve the problem of nginx multi-domain configuration independently.