搭建nginx虚拟主机——基于域名、端口和IP
admin
2023-03-29 02:41:33
0

nginx支持的虚拟主机有三种

1、基于域名的虚拟主机

2、基于IP的虚拟主机

3、基于端口的虚拟主机


一、基于域名构建

1、编译安装nginx服务

2、配置DNS域名解析服务

3、配置虚拟主机

a、创建自测网页

[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、重载服务

systemctl restart nginx
netstat -ntap | grep 80

d、访问测试

www.kgc.com
www.accp.com

二、基于端口

a、创建另一个端口的测试网页

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# echo "this is kgc 8080 web" > kgc/index.html

b、编辑nginx.conf配置文件,仅修改监听地址



    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服务

systemctl restart nginx
netstat -ntap | grep 80

d、测试网页

www.accp.com
www.accp.com8080

三、基于IP

1、修改网页配置文件中的区域数据配置文件

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服务

systemctl restart nginx
netstat -ntap | grep 80

d、测试网页

192.168.109.137
192.168.109.134


相关内容

热门资讯

玩家最新攻略“西兵互娱有没有挂... 家人们!今天小编来为大家解答西兵互娱透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买很...
玩家攻略科普“青橙竞技是不是有... 家人们!今天小编来为大家解答青橙竞技透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买很...
今日重大消息“四方河南麻将怎么... 今日重大消息“四方河南麻将怎么装挂?”(太坑了果然有挂)您好,四方河南麻将这个游戏其实有挂的,确实是...
玩家分享攻略“同城游贵阳捉鸡麻... 家人们!今天小编来为大家解答同城游贵阳捉鸡麻将透视挂怎么安装这个问题咨询软件客服徽9784099的挂...
最新引进“天蝎牛牛开挂器?”(... 有 亲,根据资深记者爆料天蝎牛牛是可以开挂的,确实有挂(咨询软件无需打开...
【今日要闻】“樱花炸/金/花开... 有 亲,根据资深记者爆料樱花炸/金/花是可以开挂的,确实有挂(咨询软件无...
【第一财经】“上海明星麻将开挂... 【第一财经】“上海明星麻将开挂器?”(透视曝光猫腻)您好,上海明星麻将这个游戏其实有挂的,确实是有挂...
最新引进“微友山西麻将到底是不... 网上科普关于“微友山西麻将有没有挂”话题很是火热,小编也是针对微友山西麻将作*弊开挂的方法以及开挂对...
新能源车高速公路电量耗尽,司乘... 澎湃新闻记者 覃明近日,广东省公安厅微信公众号“广东交警”发布一则案例,一辆新能源汽车的驾驶人和乘客...
我来教教您“福建众娱到底是不是... 网上科普关于“福建众娱有没有挂”话题很是火热,小编也是针对福建众娱作*弊开挂的方法以及开挂对应的知识...