亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

nginx基于域名,端口,不同IP的虛擬主機設(shè)置的實現(xiàn)

 更新時間:2020年11月09日 11:38:57   作者:peihhua  
這篇文章主要介紹了nginx基于域名,端口,不同IP的虛擬主機設(shè)置,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

一. nginx 虛擬主機的設(shè)置

利用虛擬主機,不用為每個要運行的網(wǎng)站提供一臺單獨的Nginx服務(wù)器或單獨運行一組Nginx進程,虛擬主機提供了在同一臺服務(wù)器,同一組 Nginx進程上運行多個網(wǎng)站的功能。跟Apache一樣,Nginx也可以配置多種類型的虛擬主機,分別是基于IP的虛擬主機、基于域名的虛擬主機、基于端口的虛擬主機。
使用Nginx搭建虛擬主機服務(wù)器時,每個虛擬Web站點擁有獨立的“serverf”配置段,各自監(jiān)聽的IP地址、端口號可以單獨指定,當然網(wǎng)站名稱也是不同的。

1.1 基于域名的虛擬主機

1.11 改測試系統(tǒng)的WIN10的映射文件host

1)修改host文件

修改windos客戶機的C:\Windows\System32\drivers\etc\hosts文件,加入www.51xit.top和www.52xit.top這兩個域名,它們都指向同一個服務(wù)器IP地址,用于實現(xiàn)不同的域名訪問不同的虛擬主機。

20.0.0.24 www.lph.com www.dzg.com

2)開啟nginx服務(wù)對域名進行初測試

無論是測試www.lph.com 還是www.dzg.com都是指向的服務(wù)器20.0.0.24的網(wǎng)站測試首頁。

瀏覽器中訪問:www.lph.com

在這里插入圖片描述

瀏覽器中訪問:www.dzg.com

在這里插入圖片描述

后面要實現(xiàn)的是訪問不同的域名可以訪問到不同的網(wǎng)點。

1.12 各個網(wǎng)站的目錄和測試首頁

[root@localhost~]# mkdir -p /var/www/html/lph/       ####創(chuàng)建www.lph.com的根目錄
[root@localhost~]# mkdir -p /var/www/html/dzg/       ####創(chuàng)建www.dzg.com的根目錄
[root@localhost~]# echo "www.lph.com" >> /var/www/html/lph/index.html
[root@localhost~]# echo "www.dzg.com" >> /var/www/html/dzg/index.html

1.13 主配置文件

修改配置文件/usr/local/nginx/conf/nginx.conf,把配置文件中的server{}代碼段全部去掉,加入2個新的server{}段,對應(yīng)2個域名。

1)配置文件的修改

####省略####
  server {
    listen    80;
    server_name www.lph.com;
    charset utf-8;
    access_log logs/www.lph.com.access.log;
    location / {
      root  /var/www/html/lph;
      index index.html index.htm;
    }
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
      root  html;
    }
  }
    server {
    listen    80;
    server_name www.dzg.com;
    charset utf-8;
    access_log logs/www.dzg.com.access.log;
    location / {
      root  /var/www/html/dzg;
      index index.html index.htm;
    }
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
      root  html;
    }
  }
  ####省略####

2)客戶機測試
訪問www.lph.com

在這里插入圖片描述

訪問www.dzg.com

在這里插入圖片描述

1.2 基于端口的虛擬主機

只需要一個IP地址的不同端口實現(xiàn)訪問不同的網(wǎng)點

1.21 配置文件的修改

server {
  listen   20.0.0.24:80;
  server_name www.lph.com;
  charset utf-8;
  access_log logs/www.lph.com.access.log;
  location / {
    root  /var/www/html/lph;
    index index.html index.htm;
  }
  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root  html;
  }
}
server {
  listen    20.0.0.24:8080;
  server_name www.dzg.com;
  charset utf-8;
  access_log logs/www.dzg8080.com.access.log;
  location / {
    root  /var/www/html/dzg;
    index index.html index.htm;
  }
  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root  html;
  }
}

1.22 客戶機的測試

訪問www.lph.com:80和訪問20.0.0.24:80

在這里插入圖片描述

訪問www.dzg.com:8080及訪問20.0.0.24:8080

在這里插入圖片描述

1.3 基于不同IP的虛擬主機

主機配置兩個IP地址
20.0.0.24 192.168.100.24

1.31 添加一張網(wǎng)卡并設(shè)置IP

[root@localhost ~]# nmcli connection    #復制新增網(wǎng)卡的地址
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens36
[root@localhost network-scripts]# vi ifcfg-ens36
NAME=ens36
UUID=ee2dccf4-cc4a-34bc-9cea-37e7d528cd27   #粘貼新增網(wǎng)卡的地址
DEVICE=ens36
ONBOOT=yes
IPADDR=192.168.100.26
NETMASK=255.255.255.0
GATEWAY=192.168.100.1

[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifdown ens36
[root@localhost ~]# ifup ens36

#######打開電腦cmd ping一下   ping通繼續(xù)

1.32 修改客戶機的host 文件

20.0.0.0.24 www.lph.com
192.168.100.24 www.dzg.com

1.33 修改配置文件

server {
  listen   20.0.0.24:80;
  server_name www.lph.com;
  charset utf-8;
  access_log logs/www.lph.com.access.log;
  location / {
    root  /var/www/html/lph;
    index index.html index.htm;
  }
  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root  html;
  }
}
server {
  listen    192.168.100.24:80;
  server_name www.dzg.com;
  charset utf-8;
  access_log logs/www.dzg.com.access.log;
  location / {
    root  /var/www/html/dzg;
    index index.html index.htm;
  }
  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root  html;
  }
}

1.34 客戶機測試

訪問www.lph.com和訪問20.0.0.24

在這里插入圖片描述

訪問www.dzg.com和訪問192.168.100.24

在這里插入圖片描述

到此這篇關(guān)于nginx基于域名,端口,不同IP的虛擬主機設(shè)置的實現(xiàn)的文章就介紹到這了,更多相關(guān)nginx 虛擬主機設(shè)置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論