基于域名的虛擬主機(jī).基于IP的虛擬主機(jī)基于端口的虛擬主機(jī)通過(guò)"server{}"配置段實(shí)現(xiàn)

本篇實(shí)驗(yàn)接著上一" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 網(wǎng)站運(yùn)營(yíng) > 【零基礎(chǔ)學(xué)云計(jì)算】詳述Linux系統(tǒng)中Nginx虛擬主機(jī)的配置

【零基礎(chǔ)學(xué)云計(jì)算】詳述Linux系統(tǒng)中Nginx虛擬主機(jī)的配置

時(shí)間:2023-07-12 11:21:02 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)

時(shí)間:2023-07-12 11:21:02 來(lái)源:網(wǎng)站運(yùn)營(yíng)

【零基礎(chǔ)學(xué)云計(jì)算】詳述Linux系統(tǒng)中Nginx虛擬主機(jī)的配置:

Nginx虛擬主機(jī)應(yīng)用

Nginx支持的虛擬主機(jī)有三種

通過(guò)"server{}"配置段實(shí)現(xiàn)

基于域名的虛擬主機(jī)

[root@localhost nginx-1.12.2]# mkdir -p /var/www/html/accp //遞歸創(chuàng)建accp網(wǎng)頁(yè)站點(diǎn)目錄

[root@localhost nginx-1.12.2]# mkdir -p /var/www/html/kgc //遞歸創(chuàng)建kgc網(wǎng)頁(yè)站點(diǎn)目錄

[root@localhost nginx-1.12.2]# cd /var/www/html/ //進(jìn)入站點(diǎn)目錄

[root@localhost html]# ls //查看

accp kgc

[root@localhost html]# echo "this is kgc web" > kgc/index.html //創(chuàng)建站點(diǎn)文件

[root@localhost html]# echo "this is accp web" > accp/index.html //創(chuàng)建站點(diǎn)文件

[root@localhost html]# ls accp/ //查看accp站點(diǎn)目錄

index.html

[root@localhost html]# ls kgc/ //查看kgc站點(diǎn)目錄

index.html

[root@localhost conf]# vim /etc/named.rfc1912.zones //編輯DNS服務(wù)區(qū)域配置文件

...//省略部分內(nèi)容...

zone "kgc.com" IN {

type master;

file "kgc.com.zone";

allow-update { none; };

};

zone "accp.com" IN {

type master;

file "accp.com.zone"; //添加accp網(wǎng)頁(yè)域名解析

allow-update { none; };

};

...//省略部分內(nèi)容...

:wq

[root@localhost conf]# cd /var/named/

[root@localhost named]# cp -p named.localhost kgc.com.zone //復(fù)制區(qū)域數(shù)據(jù)文件

[root@localhost named]# vim kgc.com.zone //編輯kgc區(qū)域數(shù)據(jù)文件

$TTL 1D

@ IN SOA @ rname.invalid. (

0 ; serial

1D ; refresh

1H ; retry

1W ; expire

3H ) ; minimum

NS @

A 127.0.0.1

www IN A 192.168.144.133

:wq

[root@localhost named]# cp -p kgc.com.zone accp.com.zone

//復(fù)制kgc區(qū)域數(shù)據(jù)文件保持權(quán)限不變,復(fù)制為accp區(qū)域數(shù)據(jù)文件

[root@localhost named]# systemctl restart named //重啟DNS服務(wù)

[root@localhost init.d]# cd /usr/local/nginx/conf/

[root@localhost conf]# vim nginx.conf //編輯Nginx主配置文件

...//省略部分內(nèi)容...

server {

listen 80;

server_name www.kgc.com; //設(shè)置kgc域名訪問(wèn)條目

charset utf-8; //更改字符串類型

access_log logs/www.kgc.com.access.log; //更改日志文件名稱

location / {

root /var/www/html/kgc; //更改站點(diǎn)位置

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;

}

}

...//省略部分內(nèi)容...

:wq

[root@localhost conf]# nginx -t //檢測(cè)語(yǔ)法

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost conf]# service nginx restart //重啟服務(wù)

[root@localhost conf]# systemctl restart named //重啟DNS服務(wù)

基于端口的虛擬主機(jī)

[root@localhost conf]# vim nginx.conf //編輯Nginx主配置文件

...//省略部分內(nèi)容...

# 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; //注釋掉此部分內(nèi)容

# index index.html index.htm;

# }

# error_page 500 502 503 504 /50x.html;

# location = /50x.html {

# root html;

# }

# }




server {

listen 192.168.144.133:80; //端口條目錢添加IP地址

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 { //復(fù)制上面部分的內(nèi)容

listen 192.168.144.133:8080; //設(shè)置相同IP監(jiān)聽(tīng)不同端口

server_name www.accp.com;

charset utf-8;

access_log logs/www.accp8080.com.access.log; //更改日志文件名稱

location / {

root /var/www/html/accp8080; //整改站點(diǎn)文件目錄名稱

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

...//省略部分內(nèi)容...

:wq

[root@localhost conf]# cd /var/www/html/ //進(jìn)入站點(diǎn)目錄

[root@localhost html]# mkdir accp8080 //創(chuàng)建目錄

[root@localhost html]# echo "this is accp8080 web" > accp8080/index.html //編輯網(wǎng)頁(yè)內(nèi)容

[root@localhost html]# cd /usr/local/nginx/conf/

[root@localhost conf]# nginx -t //檢測(cè)語(yǔ)法

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost conf]# service nginx restart //重啟服務(wù)

[root@localhost conf]# netstat -ntap | grep 80 //查看端口

tcp 0 0 192.168.144.133:8080 0.0.0.0:* LISTEN 11967/nginx: master

tcp 0 0 192.168.144.133:80 0.0.0.0:* LISTEN 11967/nginx:

基于不同IP的虛擬主機(jī)

[root@localhost conf]# ifconfig //查看新添加的網(wǎng)卡信息,并記錄IP地址

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255

inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet)

RX packets 67362 bytes 72060261 (68.7 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 16836 bytes 1825469 (1.7 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0




ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.144.145 netmask 255.255.255.0 broadcast 192.168.144.255

inet6 fe80::deb1:3cec:3e26:5ec2 prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:5b:d3:aa txqueuelen 1000 (Ethernet)

RX packets 6 bytes 926 (926.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 27 bytes 4513 (4.4 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@localhost conf]# vim /var/named/kgc.com.zon //更改DNS區(qū)域數(shù)據(jù)文件中kgc網(wǎng)頁(yè)解析的IP地址

$TTL 1D

@ IN SOA @ rname.invalid. (

0 ; serial

1D ; refresh

1H ; retry

1W ; expire

3H ) ; minimum

NS @

A 127.0.0.1

www IN A 192.168.144.145 //更改為新添加網(wǎng)卡的IP地址

:wq

[root@localhost conf]# vim nginx.conf //編輯主配置文件

...//省略部分內(nèi)容...

server {

listen 192.168.144.145:80; //去掉上面配置基于端口時(shí)全面添加的注釋,并添加監(jiān)聽(tīng)的IP地址

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.144.133: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.144.133:8080;

# server_name www.accp.com;

# charset utf-8;

# access_log logs/www.accp8080.com.access.log; //注釋掉此部分內(nèi)容

# location / {

# root /var/www/html/accp8080;

# index index.html index.htm;

# }

# error_page 500 502 503 504 /50x.html;

# location = /50x.html {

# root html;

# }

# }

...//省略部分內(nèi)容...

:wq

[root@localhost conf]# nginx -t //檢測(cè)語(yǔ)法

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost conf]# service nginx restart //重啟服務(wù)

[root@localhost conf]# systemctl restart named //重啟DNS服務(wù)

寫(xiě)在最后:

本專欄所有文章均為杭州課工場(chǎng)學(xué)員投稿,如有問(wèn)題歡迎指出討論,未經(jīng)允許,禁止轉(zhuǎn)載!

關(guān)鍵詞:系統(tǒng),虛擬,主機(jī),配置,基礎(chǔ)

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉