Nginx仮想ホスト3(ポートとドメイン名に基づく)

ドメイン名ベースの仮想ホスティング:異なるドメイン名に同じIP

ポートベースの仮想ホスト:異なるサイトのコンテンツを区別するためにドメイン名、IPを使用せず、異なるTCPポート番号を使用する

IPアドレスに基づく仮想ホスト:異なるドメイン名と異なるIP(広く使用されていない、ネットワークインターフェイスを追加する必要があります)

以来IPのアドレス-ベースのバーチャルホストがネットワークインターフェイスを追加する必要があり、広く使用されていない、次は、ドメインベースの仮想ホストとポートベースのバーチャルホストを紹介します

1. Nginxポートベースの仮想ホスト

[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仮想ホスト(上記の構成操作に基づく)

 構成は上記と同じです

おすすめ

転載: blog.csdn.net/yeyslspi59/article/details/108050321