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

首頁 > 網站 > Nginx > 正文

Nginx 虛擬主機配置的三種方式(基于域名)

2024-08-30 12:24:43
字體:
來源:轉載
供稿:網友

Nginx配置虛擬主機支持3種方式:基于IP的虛擬主機配置,基于端口的虛擬主機配置,基于域名的虛擬主機配置。

詳解Nginx 虛擬主機配置的三種方式(基于IP) http://www.survivalescaperooms.com/article/149774.htm

詳解Nginx 虛擬主機配置的三種方式(基于端口) http://www.survivalescaperooms.com/article/14978.htm

3、Nginx基于域名的虛擬主機配置

使用基于域名的虛擬主機配置是比較流行的方式,可以在同一個IP上配置多個域名并且都通過80端口訪問。

3.1 假設服務器有個IP地址為192.168.2.155

[root@localhost ~]# ifconfig ens33:5 192.168.2.155/24 up[root@localhost ~]# ifconfigens33:5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500  inet 192.168.2.155 netmask 255.255.255.0 broadcast 192.168.2.255  ether 00:0c:29:16:90:ae txqueuelen 1000 (Ethernet)

3.2 192.168.2.155對應的域名如下,配置主機的host文件便于測試

[root@localhost ~]# vim /etc/hosts[root@localhost ~]# cat /etc/hosts|grep 192.168.2.155192.168.2.155 www.oa.com192.168.2.155 www.bbs.com192.168.2.155 www.test.com

3.3 建立虛擬主機存放網頁的根目錄,并創建首頁文件index.html

[root@localhost ~]# cd /data/www/[root@localhost www]# mkdir www.oa.com[root@localhost www]# mkdir www.bbs.com[root@localhost www]# mkdir www.test.com[root@localhost www]# echo www.oa.com > www.oa.com/index.html[root@localhost www]# echo www.bbs.com > www.bbs.com/index.html[root@localhost www]# echo www.test.com > www.test.com/index.html

3.4 修改nginx.conf,將虛擬主機配置文件包含進主文件

[root@localhost /]# cd /usr/local/nginx/conf/[root@localhost conf]# lsfastcgi.conf   fastcgi_params   koi-utf mime.types   nginx.conf   scgi_params   uwsgi_params   win-utffastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default[root@localhost conf]# vim nginx.conf

在nginx.conf文件末尾加入以下配置

# 在http段中找到以下內容并刪除每行前面的“#” log_format main '$remote_addr - $remote_user [$time_local] "$request" '      '$status $body_bytes_sent "$http_referer" '      '"$http_user_agent" "$http_x_forwarded_for"';# 配置文件結尾的最后一個“}”之前加入以下語句,如下所示include vhost/*.conf

3.5 編輯每個域名的配置文件(每個虛擬主機的配置文件)

[root@localhost conf]# cd vhost/[root@localhost vhost]# cat www.oa.com.conf server {  listen  192.168.2.155:80;  server_name www.oa.com;  access_log /data/logs/www.oa.com.log main;  error_log /data/logs/www.oa.com.error.log;  location / {   root /data/www/www.oa.com;   index index.html index.htm;  } }[root@localhost vhost]# cat www.bbs.com.conf server {  listen  192.168.2.155:80;  server_name www.bbs.com;  access_log /data/logs/www.bbs.com.log main;  error_log /data/logs/www.bbs.com.error.log;  location / {   root /data/www/www.bbs.com;   index index.html index.htm;  } }[root@localhost vhost]# cat www.test.com.conf server {  listen  192.168.2.155:80;  server_name www.test.com;  access_log /data/logs/www.test.com.log main;  error_log /data/logs/www.test.com.error.log;  location / {   root /data/www/www.test.com;   index index.html index.htm;  } }[root@localhost vhost]# cat /data/www/www.oa.com/index.htmlwww.oa.com[root@localhost vhost]# cat /data/www/www.bbs.com/index.htmlwww.bbs.com[root@localhost vhost]# cat /data/www/www.test.com/index.htmlwww.test.com            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云安县| 元江| 繁昌县| 微博| 庄浪县| 武城县| 德江县| 富顺县| 叙永县| 大丰市| 青龙| 汉中市| 孟连| 塔城市| 阿拉善盟| 黔西县| 沭阳县| 芦溪县| 丽水市| 昌黎县| 宁明县| 青州市| 赞皇县| 九龙坡区| 西昌市| 东辽县| 从化市| 磐石市| 灵川县| 南澳县| 临江市| 望都县| 江源县| 遵义县| 阳信县| 平阴县| 麻阳| 天门市| 阿克苏市| 博爱县| 大埔县|