nginx配置虛擬主機之不同埠和不同IP位址

2022-07-24 11:27:07 字數 4386 閱讀 5803

配置nginx虛擬主機不同埠和不同ip位址,和上編nginx基於網域名稱配置虛擬主機博文類似,請先參考。

zxl.com網域名稱不同埠,配置檔案內容如下:12

3456

78910

11[root@zxl-nginx conf.d]# cat zxl.com.conf

server

}

bbs.com網域名稱不同埠,配置檔案內容如下:12

3456

78910

11[root@zxl-nginx conf.d]# cat bbs.com.conf

server

}12

3456

78[root@zxl-nginx conf.d]# netstat -nplt|grep nginx

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   listen      3476/nginx

tcp        0      0 0.0.0.0:81                  0.0.0.0:*                   listen      3476/nginx

tcp        0      0 0.0.0.0:82                  0.0.0.0:*                   listen      3476/nginx

[root@zxl-nginx conf.d]# nginx -t

nginx: the configurationfile/usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configurationfile/usr/local/nginx/conf/nginx.conftestis successful

[root@zxl-nginx conf.d]# nginx -s reload

測試結果如下:12

34[root@zxl-nginx conf.d]# elinks  --dump

this is a site www.zxl.comtest!

[root@zxl-nginx conf.d]# elinks  --dump

this is a site www.bbs.comtest!12

[root@zxl-nginx conf.d]# ifconfig eth0:1 192.168.33.132

[root@zxl-nginx conf.d]# ifconfig eth0:2 192.168.33.133

檢視配置ip位址12

3456

78910

1112

13[root@zxl-nginx conf.d]# ip a

1: lo: mtu 16436 qdisc noqueue state unknown

link/loopback00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8scope host lo

inet6 ::1/128scope host

valid_lft forever preferred_lft forever

2: eth0: 

mtu 1500 qdisc pfifo_fast state up qlen 1000

link/ether00:50:56:32:9b:32 brd ff:ff:ff:ff:ff:ff

inet 192.168.33.131/24brd 192.168.33.255 scope global eth0

inet 192.168.33.132/24brd 192.168.33.255 scope global secondary eth0:1

inet 192.168.33.133/24brd 192.168.33.255 scope global secondary eth0:2

inet6 fe80::250:56ff:fe32:9b32/64scope link

valid_lft forever preferred_lft forever

不同ip位址的虛擬主機配置檔案如下:

ip位址192.168.33.132配置檔案內容12

3456

78910

11[root@zxl-nginx conf.d]# cat zxl.com.conf

server

}

ip位址192.168.33.133配置檔案內容12

3456

78910

11[root@zxl-nginx conf.d]# cat bbs.com.conf

server

}12

34[root@zxl-nginx conf.d]# nginx -t

nginx: the configurationfile/usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configurationfile/usr/local/nginx/conf/nginx.conftestis successful

[root@zxl-nginx conf.d]# nginx -s reload12

345測試結果如下:

[root@zxl-nginx conf.d]# elinks  --dump

#this is a site www.zxl.com test! this is a site 192.168.33.132 test!

[root@zxl-nginx conf.d]# elinks  --dump

#this is a site www.bbs.com test! this is a site 192.168.33.133 test!

Nginx虛擬主機配置

0.nginx簡介 nginx engine x 是乙個高效能的 http 和 反向 伺服器,也是乙個 imap pop3 smtp 伺服器。nginx 已經因為它的穩定性 豐富的功能集 示例配置檔案和低系統資源的消耗而聞名了。1.nginx使用注意事項 2.nginx相關檔案 3.nginx虛擬主...

nginx虛擬主機配置

就是在一台伺服器啟動多個 如何區分不同的 1 網域名稱不同 2 埠不同 乙個server節點就是乙個虛擬主機,可以配置多個server,配置多個虛擬主機,html是nginx安裝目錄下的html目錄。乙個網域名稱對應乙個ip位址,乙個ip位址可以被多個網域名稱繫結。本地測試可以修改hosts檔案。修...

nginx虛擬主機配置

虛擬主機的配置有多種 一 color green b 基於ip的虛擬主機 b color 二 color green b 基於埠的虛擬主機 b color 三 color green b 基於網域名稱的虛擬主機 b color 對於nginx要實現虛擬主機,通過nginx.cnf中的server進行...