人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

基于域名、端口和IP搭建nginx虛擬主機(jī)

發(fā)布日期:2022-02-22 08:33 | 文章來源:gibhub

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

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

2、基于IP的虛擬主機(jī)

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

一、基于域名構(gòu)建

1、編譯安裝nginx服務(wù)

2、配置DNS域名解析服務(wù)

3、配置虛擬主機(jī)

a、創(chuàng)建自測網(wǎng)頁

[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、訪問測試

www.kgc.com
www.accp.com

二、基于端口

a、創(chuàng)建另一個端口的測試網(wǎng)頁

[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、測試網(wǎng)頁

www.accp.com
www.accp.com8080

三、基于IP

1、修改網(wǎng)頁配置文件中的區(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、測試網(wǎng)頁

192.168.109.137
192.168.109.134

總結(jié)

以上所述是小編給大家介紹的基于域名、端口和IP搭建nginx虛擬主機(jī),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對本站網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

美國服務(wù)器租用

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部