国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > Nginx > 正文

nginx 配置虛擬主機(jī),實(shí)現(xiàn)在一個(gè)服務(wù)器可以訪問(wèn)多個(gè)網(wǎng)站的方法

2024-08-30 12:25:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

在一臺(tái)服務(wù)器上,訪問(wèn)不同的網(wǎng)站

通常有兩種區(qū)分方式:

1.通過(guò)監(jiān)聽(tīng)的端口號(hào)

2.通過(guò)域名

1.通過(guò)端口訪問(wèn)不同的主機(jī):

Nginx的配置文件:

/usr/local/nginx/conf/nginx.conf

Centos文件默認(rèn)編碼格式 latin1

查看編碼格式的命令: :set fileencoding

#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid    logs/nginx.pid;events {  worker_connections 1024;}##一個(gè)http節(jié)點(diǎn)http {    include    mime.types;  default_type application/octet-stream;  #log_format main '$remote_addr - $remote_user [$time_local] "$request" '  #         '$status $body_bytes_sent "$http_referer" '  #         '"$http_user_agent" "$http_x_forwarded_for"';  #access_log logs/access.log main;  sendfile    on;  #tcp_nopush   on;  #keepalive_timeout 0;  keepalive_timeout 65;  #gzip on; #server 節(jié)點(diǎn),即 你需要訪問(wèn)網(wǎng)站的配置 #一個(gè)server節(jié)點(diǎn),就是一個(gè)虛擬主機(jī)  server {    listen    80;  #監(jiān)聽(tīng)的端口號(hào),訪問(wèn)網(wǎng)站 默認(rèn)是80端口    server_name localhost;  #即訪問(wèn)的域名    #charset koi8-r;    #access_log logs/host.access.log main;    location / {  #定位      root  html;  #定位的是nginx根目錄下的 html文件夾      index index.html index.htm;  #設(shè)置網(wǎng)站首頁(yè)    }  }}

此時(shí) 可以配置多個(gè)server,也就是配置了不同的主機(jī)

添加虛擬主機(jī):(通過(guò)端口號(hào) 區(qū)別)

server {    listen    81;    server_name localhost;    #charset koi8-r;    #access_log logs/host.access.log main;    location / {      root  html-81;  #nginx根目錄下 新建的html81 文件夾      index index.html index.htm;    ``  }

編輯好文件之后,我們重新加載配置文件

通過(guò)命令: ./nginx -s reload

效果:

我們知道,當(dāng)一個(gè)服務(wù)器上配置多個(gè)網(wǎng)站時(shí),我們不可能通過(guò)端口號(hào)來(lái)區(qū)分它們,所以接下來(lái) 我需要通過(guò)域名來(lái)區(qū)分

2.通過(guò)域名區(qū)分不同的虛擬主機(jī)

什么是域名??

域名就是網(wǎng)址

例如:www.baidu.com

通常我們?cè)谠L問(wèn)域名的時(shí)候,我們需要通過(guò)dns服務(wù)器解析域名

Dns服務(wù)器:把域名解析為ip地址。保存的就是域名和ip的映射關(guān)系。

一個(gè)域名對(duì)應(yīng)一個(gè)ip地址,一個(gè)ip地址可以被多個(gè)域名綁定。

本地測(cè)試可以修改hosts文件。

修改window的hosts文件:(C:/Windows/System32/drivers/etc)

可以配置域名和ip的映射關(guān)系,如果hosts文件中配置了域名和ip的對(duì)應(yīng)關(guān)系,不需要走dns服務(wù)器!!!!

在剛剛的nginx.conf文件下 繼續(xù)配置:

server {    listen    80;    server_name www.taobao.com;    #charset koi8-r;    #access_log logs/host.access.log main;    location / {      root  html-taobao;      index index.html index.htm;    }  }  server {    listen    80;    server_name www.baidu.com;    #charset koi8-r;    #access_log logs/host.access.log main;    location / {      root  html-baidu;      index index.html index.htm;    }  }}            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 南雄市| 同江市| 万山特区| 青岛市| 河南省| 宁津县| 修水县| 桦甸市| 深圳市| 盈江县| 罗甸县| 布尔津县| 锡林郭勒盟| 广东省| 朝阳县| 峨山| 十堰市| 北票市| 贺州市| 岢岚县| 鄂伦春自治旗| 庐江县| 沿河| 阿克苏市| 诏安县| 宣威市| 玛多县| 定结县| 宾川县| 桃园市| 准格尔旗| 赣榆县| 阳江市| 田东县| 固镇县| 石柱| 竹北市| 新和县| 庆云县| 望都县| 共和县|