Configure the server -- Nginx add multiple second-level subdomains and nginx subdomains

Source: Internet
Author: User
Tags subdomain subdomain name

Configure the server -- Nginx add multiple second-level subdomains and nginx subdomains
Nginx multi-file configuration second-level subdomain name (recommended)

First, add resolution in your domain name console. Here we use adding a blog prefix as an example.

I use hichinaResolution settingsMediumAdd resolution

Host records: The second-level domain name you want
Record Value: Your IP address

After the sub-domain name is saved, the first step is to resolve the sub-domain name to our server.

Step 2: Add a configuration file

Enter the nginx/confIn the configuration folder, Editnginx.confFile

[root@iZ2844brz0xZ ~]# cd /usr/local/nginx/conf/[root@iZ2844brz0xZ ~]# vim nginx.conf

InhttpAdd the following statement to the module:

include /usr/local/nginx/conf/sites-enabled/*.conf;

Tell the configuration file to include/sites-enabledAll.confConfiguration file.:wqSave.

In this case, we create/sites-enabledFolder, and addblog.***.com.confFile

[root@iZ2844brz0xZ conf]# mkdir sites-enabled[root@iZ2844brz0xZ sites-enabled]# vim blog.***.com.conf

Add

Server {listen 80; # listener port server_name blog. ***. com; # bind the domain name root/usr/local/nginx/html/blog/; # The website root directory. We recommend that you use the absolute path index. php index.html index.htm; # default file # Add resolution location for php ~ \. Php $ {fastcgi_pass 127.0.0.1: 9000; fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; include/usr/local/nginx/conf/fastcgi_params;} # add error pages for search engine indexing and good user experience error_page 404/404 .html; location/404.html {root/usr/local/nginx/html/;} error_page 500 502 503 x.html; location =/50x.html {root/usr/local/nginx/html /;}}

Content can be added by yourself

Configure a second-level subdomain name for a single Nginx File

Innginx.confFileserverAdd the following statement to the module

if ( $host ~* (\b(?!www\b)\w+)\.\w+\.\w+ ) { set $subdomain /$1;}location / { root html$subdomain; index index.html index.php index.htm index;}

The corresponding folder can be parsed.

Restart nginx.

[root@iZ2844brz0xZ sites-enabled]# /usr/local/nginx/sbin/nginx -s reload
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.