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 settings
MediumAdd 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/conf
In the configuration folder, Editnginx.conf
File
[root@iZ2844brz0xZ ~]# cd /usr/local/nginx/conf/[root@iZ2844brz0xZ ~]# vim nginx.conf
Inhttp
Add the following statement to the module:
include /usr/local/nginx/conf/sites-enabled/*.conf;
Tell the configuration file to include/sites-enabled
All.conf
Configuration file.:wq
Save.
In this case, we create/sites-enabled
Folder, and addblog.***.com.conf
File
[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.conf
Fileserver
Add 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.