There are three types of virtual hosts supported by nginx 1. Domain name-based virtual hosting 2. IP-based virtual hosting 3. Port-based virtual hosts 1. Building based on domain name 1. Compile and install nginx service 2. Configure DNS domain name resolution service 3. Configure virtual host a. Create a self-test web page [root@localhost named]# cd [root@localhost ~]# mkdir -p /var/www/html/kgc [root@localhost ~]# mkdir -p /var/www/html/accp [root@localhost ~]# ls /var/www/html/accp kgc [root@localhost ~]# cd /var/www/html/ [root@localhost html]# echo "this kgc web" > kgc/index.html [root@localhost html]# echo "this accp web" > accp/index.html b. Edit the nginx.conf configuration file vim /usr/local/nginx/conf/nginx.conf include conf.d/*.conf; server { listen 80; server_name www.kgc.com; charset utf-8; access_log logs/www.kgc.com.access.log; location / { root /var/www/html/kgc; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name www.accp.com; charset utf-8; access_log logs/www.accp.com.access.log; location / { root /var/www/html/accp; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } c. Overload service systemctl restart nginx netstat -ntap | grep 80 d. Access test www.kgc.com 2. Port-based a. Create a test webpage for another port [root@localhost ~]# cd /var/www/html/ [root@localhost html]# echo "this is kgc 8080 web" > kgc/index.html b. Edit the nginx.conf configuration file and only modify the listening address server { listen 192.168.109.137:80; server_name www.accp.com; charset utf-8; access_log logs/www.accp.com.access.log; location / { root /var/www/html/accp; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 192.168.109.137:8080; server_name www.accp.com; charset utf-8; access_log logs/www.accp8080.com.access.log; location / { root /var/www/html/accp8080; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } c. Reload nginx service systemctl restart nginx netstat -ntap | grep 80 d. Test web page www.accp.com 3. Based on IP 1. Modify the regional data configuration file in the web page configuration file vim /var/named/kgc.com.zone systemctl restart named 2. Edit the configuration in nginx.conf and modify the IP address server { listen 192.168.109.137:80; server_name www.kgc.com; charset utf-8; access_log logs/www.kgc.com.access.log; location / { root /var/www/html/kgc; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 192.168.109.134:80; server_name www.accp.com; charset utf-8; access_log logs/www.accp.com.access.log; location / { root /var/www/html/accp; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } c. Reload nginx service systemctl restart nginx netstat -ntap | grep 80 d. Test web page 192.168.109.137 192.168.109.134 Summarize The above is what I introduced to you about building nginx virtual hosts based on domain names, ports, and IP addresses. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Import backup between mysql database and oracle database
>>: List rendering instructions for efficient development of Vue front-end
How to configure custom path aliases in Vue In ou...
Flex Layout Flex is the abbreviation of Flexible ...
1. Cause The requirement is to display two lines,...
Table of contents Storage Engine Storage engines ...
Preface The role of process management: Determine...
Install MySQL 8.0 docker run -p 63306:3306 -e MYS...
Basic Introduction to Floating In the standard do...
The purpose of using cache is to reduce the press...
Background: I'm working on asset reporting re...
MySQL downloads for all platforms are available a...
Table of contents Overview Single file components...
Preface: Recently, I encountered a management sys...
Table of contents Nginx proxies two socket.io ser...
Phenomenon Start the Docker container docker run ...
Table of contents Preface VMware clone virtual ma...