Nginx virtual host 3 (based on port and domain name)

Domain name-based virtual hosting: Same IP for different domain names

Port-based virtual host: Do not use domain name, IP to distinguish the content of different sites, but use different TCP port numbers

Virtual host based on IP address: different domain names and different IP (need to add network interface, not widely used)

Since IP address- based virtual hosts need to add network interfaces and are not widely used, the following only introduces domain-based virtual hosts and port-based virtual hosts

1. Nginx port-based virtual host

[root@localhost ~]# yum -y install epel-release  
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# mkdir -pv  /usr/share/nginx/html/hya
[root@localhost ~]# echo "welcome to hya" > /usr/share/nginx/html/hya/index.html
[root@localhost ~]# vim /etc/nginx/nginx.conf
    server {

        listen       8080;
        server_name www.hya.com;
        location / {
                root   /usr/share/nginx/html/hya;
                index  index.html index.htm;
         }
        }
[root@localhost nginx]# systemctl  restart nginx
[root@localhost nginx]# curl 192.168.253.130:8080
welcome to hya

 2. Nginx virtual host based on domain name (based on the above configuration operation)

 The configuration is the same as above

Guess you like

Origin blog.csdn.net/yeyslspi59/article/details/108050321