【零基礎(chǔ)學(xué)云計(jì)算】搭建nginx虛擬主機(jī)——基于域名、端口和IP
時(shí)間:2023-06-29 18:06:01 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-06-29 18:06:01 來(lái)源:網(wǎng)站運(yùn)營(yíng)
【零基礎(chǔ)學(xué)云計(jì)算】搭建nginx虛擬主機(jī)——基于域名、端口和IP: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è)試
www.kgc.com
www.accp.com
二、基于端口
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)聽(tīng)地址
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 ACCP;
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è)
ACCP
www.accp.com8080
三、基于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
寫(xiě)在最后:
本專欄所有文章均為杭州課工場(chǎng)學(xué)員投稿,如有問(wèn)題歡迎指出討論,未經(jīng)允許,禁止轉(zhuǎn)載!
關(guān)鍵詞:主機(jī),虛擬,基礎(chǔ)