国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > Nginx > 正文

詳解Nginx 虛擬主機(jī)配置的三種方式(基于端口)

2024-08-30 12:24:43
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Nginx配置虛擬主機(jī)支持3種方式:基于IP的虛擬主機(jī)配置,基于端口的虛擬主機(jī)配置,基于域名的虛擬主機(jī)配置。

詳解Nginx 虛擬主機(jī)配置的三種方式(基于IP) http://www.survivalescaperooms.com/article/14974.htm

詳解Nginx 虛擬主機(jī)配置的三種方式(基于域名) http://www.survivalescaperooms.com/article/14978.htm

2、Nginx基于端口的虛擬主機(jī)配置

如一臺(tái)服務(wù)器只有一個(gè)IP或需要通過(guò)不同的端口訪問(wèn)不同的虛擬主機(jī),可以使用基于端口的虛擬主機(jī)配置。

2.1 假設(shè)服務(wù)器有個(gè)IP地址為192.168.2.154

[root@localhost conf]# ifconfig ens33:4 192.168.2.154/24 up[root@localhost conf]# ifconfigens33:4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.2.154 netmask 255.255.255.0 broadcast 192.168.2.255 ether 00:0c:29:16:90:ae txqueuelen 1000 (Ethernet)

2.2 需要配置的虛擬主機(jī)分別為7081、8081和9081,配置主機(jī)的host文件便于測(cè)試。

[root@localhost conf]# vim /etc/hosts[root@localhost conf]# cat /etc/hosts|grep 192.168.2.154192.168.2.154 www.test154.com

2.3 建立虛擬主機(jī)存放網(wǎng)頁(yè)的根目錄,并創(chuàng)建首頁(yè)文件index.html

[root@localhost conf]# cd /data/www/[root@localhost www]# mkdir port[root@localhost www]# cd port/[root@localhost port]# mkdir 7081 8081 9081[root@localhost port]# ls7081 8081 9081[root@localhost port]# echo "port 7081" > 7081/index.html[root@localhost port]# echo "port 8081" > 8081/index.html[root@localhost port]# echo "port 9081" > 9081/index.html

2.4 修改nginx.conf,將虛擬主機(jī)配置文件包含進(jìn)主文件

[root@localhost /]# cd /usr/local/nginx/conf/[root@localhost conf]# lsfastcgi.conf  fastcgi_params  koi-utf mime.types  nginx.conf  scgi_params  uwsgi_params  win-utffastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default[root@localhost conf]# vim nginx.conf

在nginx.conf文件末尾加入以下配置

# 在http段中找到以下內(nèi)容并刪除每行前面的“#” log_format main '$remote_addr - $remote_user [$time_local] "$request" '   '$status $body_bytes_sent "$http_referer" '   '"$http_user_agent" "$http_x_forwarded_for"';# 配置文件結(jié)尾的最后一個(gè)“}”之前加入以下語(yǔ)句,如下所示include vhost/*.conf

2.5 編輯每個(gè)端口的配置文件

[root@localhost vhost]# vim www.test154.7081.conf[root@localhost vhost]# cat www.test154.7081.conf server { listen 192.168.2.154:7081; # 配置成實(shí)際的域名,每個(gè)虛擬主機(jī)的配置文件域名都相同 #server_name www.test.com; access_log /data/logs/www.test154.7081.log main; error_log /data/logs/www.test154.7081.error.log; location / {  root /data/www/port/7081;  index index.html index.htm; } }[root@localhost vhost]# vim www.test154.8081.conf[root@localhost vhost]# cat www.test154.8081.conf server { listen 192.168.2.154:8081; # 配置成實(shí)際的域名,每個(gè)虛擬主機(jī)的配置文件域名都相同 #server_name www.test.com; access_log /data/logs/www.test154.8081.log main; error_log /data/logs/www.test154.8081.error.log; location / {  root /data/www/port/8081;  index index.html index.htm; } }[root@localhost vhost]# vim www.test154.9081.conf[root@localhost vhost]# cat www.test154.9081.conf server { listen 192.168.2.154:9081; # 配置成實(shí)際的域名,每個(gè)虛擬主機(jī)的配置文件域名都相同 #server_name www.test.com; access_log /data/logs/www.test154.9081.log main; error_log /data/logs/www.test154.9081.error.log; location / {  root /data/www/port/9081;  index index.html index.htm; } }            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 延寿县| 平罗县| 宿松县| 万源市| 清镇市| 循化| 瓮安县| 潞西市| 临沭县| 九台市| 广河县| 弥勒县| 盐山县| 磐安县| 萍乡市| 天津市| 台中市| 太康县| 尼玛县| 梁平县| 开化县| 皮山县| 雷山县| 惠州市| 体育| 雷州市| 广丰县| 苗栗县| 辽源市| 和田县| 榕江县| 赤城县| 沅陵县| 浏阳市| 云浮市| 名山县| 蚌埠市| 沭阳县| 昭苏县| 望都县| 绥阳县|