基于域名、端口和IP搭建nginx虛擬主機(jī)
nginx支持的虛擬主機(jī)有三種
1、基于域名的虛擬主機(jī)
2、基于IP的虛擬主機(jī)
3、基于端口的虛擬主機(jī)
一、基于域名構(gòu)建
1、編譯安裝nginx服務(wù)
2、配置DNS域名解析服務(wù)
3、配置虛擬主機(jī)
a、創(chuàng)建自測(cè)網(wǎng)頁(yè)
[root@localhost named]# cd [root@localhost ~]# mkdir -p /var/www/html/kgc [root@localhost ~]# mkdir -p /var/www/html/accp [root@localhost ~]# ls /var/www/html/accp kgc [root@localhost ~]# cd /var/www/html/ [root@localhost html]# echo "this kgc web" > kgc/index.html [root@localhost html]# echo "this accp web" > accp/index.html
b、編輯nginx.conf配置文件
vim /usr/local/nginx/conf/nginx.conf
include conf.d/*.conf;
server {
listen 80;
server_name www.kgc.com;
charset utf-8;
access_log logs/www.kgc.com.access.log ;
location / {
root /var/www/html/kgc;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp.com.access.log ;
location / {
root /var/www/html/accp;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
c、重載服務(wù)
systemctl restart nginx netstat -ntap | grep 80
d、訪問(wèn)測(cè)試
二、基于端口
a、創(chuàng)建另一個(gè)端口的測(cè)試網(wǎng)頁(yè)
[root@localhost ~]# cd /var/www/html/ [root@localhost html]# echo "this is kgc 8080 web" > kgc/index.html
b、編輯nginx.conf配置文件,僅修改監(jiān)聽地址
server {
listen 192.168.109.137:80;
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp.com.access.log ;
location / {
root /var/www/html/accp;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 192.168.109.137:8080;
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp8080.com.access.log ;
location / {
root /var/www/html/accp8080;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
c、重載nginx服務(wù)
systemctl restart nginx netstat -ntap | grep 80
d、測(cè)試網(wǎng)頁(yè)
三、基于IP
1、修改網(wǎng)頁(yè)配置文件中的區(qū)域數(shù)據(jù)配置文件
vim /var/named/kgc.com.zone systemctl restart named
2、編輯nginx.conf中的配置,修改ip地址
server {
listen 192.168.109.137:80;
server_name www.kgc.com;
charset utf-8;
access_log logs/www.kgc.com.access.log ;
location / {
root /var/www/html/kgc;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 192.168.109.134:80;
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp.com.access.log ;
location / {
root /var/www/html/accp;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
c、重載nginx服務(wù)
systemctl restart nginx netstat -ntap | grep 80
d、測(cè)試網(wǎng)頁(yè)
192.168.109.137 192.168.109.134
總結(jié)
以上所述是小編給大家介紹的基于域名、端口和IP搭建nginx虛擬主機(jī),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
Logrotate如何實(shí)現(xiàn)每小時(shí)切割日志文件
這篇文章主要介紹了Logrotate如何實(shí)現(xiàn)每小時(shí)切割日志文件問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05
Apache和Nginx的優(yōu)缺點(diǎn)詳解_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
Nginx和Apache一樣,都是HTTP服務(wù)器軟件,在功能實(shí)現(xiàn)上都采用模塊化結(jié)構(gòu)設(shè)計(jì),都支持通用的語(yǔ)言接口。下面通過(guò)本文給大家分享Apache和Nginx比較 功能對(duì)比,感興趣的朋友參考下吧2017-08-08
Nginx上配置Basic Authorization登錄認(rèn)服務(wù)證的教程
現(xiàn)在我們所使用的包括社交網(wǎng)絡(luò)API等開放平臺(tái)授權(quán)獲得用戶的用戶名和密碼一般有兩種認(rèn)證方式,一種是Basic Auth,一種是OAuth,這里我們就來(lái)看一下Nginx上配置Basic Authorization登錄認(rèn)服務(wù)證的教程2016-06-06
nginx+tomcat實(shí)現(xiàn)Windows系統(tǒng)下的負(fù)載均衡搭建教程
下面小編就為大家分享一篇nginx+tomcat實(shí)現(xiàn)Windows系統(tǒng)下的負(fù)載均衡搭建教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助2017-12-12
nginx 網(wǎng)頁(yè)匹配跳轉(zhuǎn)rewrite、location的具體使用
本文主要介紹了nginx 網(wǎng)頁(yè)匹配跳轉(zhuǎn)rewrite、location的具體使用2024-05-05
Linux平臺(tái)通過(guò)nginx和vsftpd構(gòu)建圖片服務(wù)器
這篇文章主要介紹了Linux平臺(tái)通過(guò)nginx和vsftpd構(gòu)建圖片服務(wù)器,需要的朋友可以參考下2017-05-05
Nginx配置二級(jí)域名的方法實(shí)現(xiàn)
本文主要介紹了Nginx配置二級(jí)域名的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03

