Virtual host:
One server, one httpd, nginx software to realize multiple websites
Methods: Domain-based, IP-based and port-based virtual hosting
[Create a domain name-based virtual host]
step:
1. Modify the configuration file
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.a.com; 【Set domain name】
auth_basic "welcome to my nginx";
auth_basic_user_file "/usr/local/nginx/pass";
server {
listen 80;
server_name www.b.com;
charset utf-8; [Chinese for parsing web page file content]
location / {
root www; [Webpage file path]
index index.html index.htm;
}
}
# cd /usr/local/nginx/ [Enter the webpage file storage directory to add a new directory]
# mkdir www
# vim www/index.html [Write web files]
# /usr/local/nginx/sbin/nginx -s reload [Refresh service]
2. Modify the local domain name resolution
[Because the test machine is used, there is no domain name resolution, so it is necessary to change the local domain name resolution settings]
Modify the /etc/hosts file of the client host 192.168.4.100 for domain name resolution
# vim /etc/hosts Note: [Modify on the client side]
192.168.4.5 www.a.com www.b.com
Note: The configuration file needs to end with a semicolon. If you enter Chinese in the web page file, you need to add charset utf-8 for parsing.