Use Nginx service to build multiple websites on one virtual host
- Create multiple host configuration files in the "/etc/nginx/conf.d/" directory (a server represents a website)
- Create the site directory and the home page file in the site directory; here I use the default site directory "/usr/share/nginx/html" and the default home page file "index.html", you can also modify it at will.
- Write "Windows/System32/drivers/etc/hosts" parsing file in Windows host
- Use the browser in Windows for access test
How to access the website
- Access based on the domain name has been mentioned above, so I won’t repeat it.
- Access based on address. (Only use the specified address to access)
- Access based on port.
Web page to access the principle
TIPS: When direct access "10.0.0.7" through the browser, if the monitor is not set, the default sort is open at the top of the homepage. Because the browser finds the server "10.0.0.7", it visits port 80. At this time, the Nginx main configuration file "/etc/nginx/nginx.comf" will load all the extended configuration files of "/etc/nginx/conf.d", and because there is no specific domain name matching, it will follow the order of loading The home page file of the first website is returned to the client.
Website security access configuration
- Control based on the address the user visits. Need to use nginxf access module: "ngx_http_access_module"; the figure below is some configuration instructions of the "ngx_http_access_module" module I intercepted from the Nginx official website:
Actual operation:
Access "blog.cxsnb.com/blog" on the shell command line:
TIPS: The information outside the location is the global configuration information; the information inside the location is the local information.
- Authentication according to user access; the module that needs to be used is "ngx_http_auth_basic_module"; the figure below is the configuration instructions of some "ngx_http_auth_basic_module" authentication modules that I intercepted from the Nginx official website:
actual operation:
first step: writing website extension configuration file
second Department: Create a password file (the information in the password file must be in cipher text)
Step 3: Test
TIPS: The initial permission of the password file "/etc/nginx/password/htpasswd" is 644, which is very insecure. You can change the permissions of the password file to 600 so that other users cannot get the password. But simply modify the permissions of the password file, so that when you use the browser to visit the website, it will report a "500" error. Let's explain the principle through a picture.