Multiple Domain Names are bound to Nginx on the CentOS server.

Source: Internet
Author: User
Tags centos server nginx server

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 nameIndex index.htm index.html index. php; # default fileRoot/home/www/your-domain.com; # website root directoryInclude 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.

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.