成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Nginx虛擬主機配置實例

Nginx虛擬主機

結(jié)合上篇文章:手工編譯NginxNginx虛擬主機的搭建過程,虛擬主機的概念在之前的Apache虛擬主機搭建實驗時已講述過有關(guān)知識點,原文鏈接:Apache web 虛擬主機

云州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!

結(jié)合上篇文章的配置進行下面的配置操作(Nginx服務(wù)是開啟狀態(tài))

[root@localhost named]# netstat -natp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 79214/nginx: master

Nginx虛擬主機配置

1.域名解析配置(環(huán)境準(zhǔn)備)

[root@localhost ~]# yum install -y bind
...//省略部分內(nèi)容
  dhclient.x86_64 12:4.2.5-77.el7.centos                                         
  dhcp-common.x86_64 12:4.2.5-77.el7.centos                                      
  dhcp-libs.x86_64 12:4.2.5-77.el7.centos                                        

Complete!
[root@localhost ~]# vim /etc/named.conf 
[root@localhost ~]# head -21 /etc/named.conf |tail 
options {
        listen-on port 53 { any; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        recursing-file  "/var/named/data/named.recursing";
        secroots-file   "/var/named/data/named.secroots";
        allow-query     { any; };

[root@localhost ~]# vim /etc/named.rfc1912.zones 
[root@localhost ~]# vim /etc/named.rfc1912.zones 
[root@localhost ~]# head -34 /etc/named.rfc1912.zones | tail 
zone "ll.com" IN {
        type master;
        file "ll.com.zone";
        allow-update { none; };
};

zone "cc.com" IN {
        type master;
        file "cc.com.zone";
        allow-update { none; };
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves
[root@localhost named]# cp -p named.localhost ll.com.zone
[root@localhost named]# vim ll.com.zone 
[root@localhost named]# cp -p ll.com.zone cc.com.zone
[root@localhost named]# cat ll.com.zone 
$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.68.144
[root@localhost named]# cat cc.com.zone 
$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.68.144

[root@localhost named]# systemctl start named
[root@localhost named]# systemctl stop firewalld.service 
[root@localhost named]# setenforce 
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@localhost named]# setenforce 0

2.在win10虛擬機上使用nslookup命令測試是否正常解析

Nginx虛擬主機配置實例

3.創(chuàng)建站點

[root@localhost ~]# mkdir -p /var/www/html/ll
[root@localhost ~]# mkdir -p /var/www/html/cc
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
cc  ll
[root@localhost html]# echo "this is ll test web" > ll/index.html
[root@localhost html]# echo "this is cc test web" > cc/index.html
[root@localhost html]# ls ll/
index.html
[root@localhost html]# ls cc/
index.html

4.基于不同域名的服務(wù)解析設(shè)置

[root@localhost html]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim /usr/local/nginx/conf/nginx.conf
[root@localhost conf]# sed -n '35,63p' nginx.conf
    server {
        listen       80;
        server_name  www.ll.com;
        charset utf-8;
        access_log  logs/www.ll.com.access.log;
        location / {
            root   /var/html/ll;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen       80;
        server_name  www.cc.com;
        charset utf-8;
        access_log  logs/www.cc.com.access.log;
        location / {
            root   /var/html/cc;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
[root@localhost conf]# nginx -t
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 

5.不同域名的測試

Nginx虛擬主機配置實例

Nginx虛擬主機配置實例

Nginx基于不同端口訪問

繼續(xù)根據(jù)上面的第四步的配置

[root@localhost conf]# sed -n '35,63p' nginx.conf
    server {
        listen       192.168.68.144:80;
        server_name  www.ll.com;
        charset utf-8;
        access_log  logs/www.ll.com.access.log;
        location / {
            root   /var/www/html/ll;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen      192.168.68.144:8080;
        server_name  www.cc.com;
        charset utf-8;
        access_log  logs/www.cc8080.com.access.log;
        location / {
            root   /var/www/html/cc8080;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
     nginx -t
[root@localhost conf]# nginx -t
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 

檢測:

Nginx虛擬主機配置實例

Nginx基于不同IP地址訪問

添加一塊網(wǎng)卡選擇nat模式

我的是192.168.68.150

1.修改區(qū)域數(shù)據(jù)配置文件

[root@localhost conf]# vim /var/named/cc.com.zone 
[root@localhost conf]# cat /var/named/cc.com.zone 
$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.68.150
[root@localhost conf]# systemctl restart named

查看解析是否成功:

Nginx虛擬主機配置實例

2.更改配置文件

[root@localhost conf]# vim nginx.conf
[root@localhost conf]# sed -n '35,63p' nginx.conf
    server {
        listen      192.168.68.144:80;
        server_name  www.ll.com;
        charset utf-8;
        access_log  logs/www.ll.com.access.log;
        location / {
            root   /var/www/html/ll;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen      192.168.68.150:80;
        server_name  www.cc.com;
        charset utf-8;
        access_log  logs/www.cc.com.access.log;
        location / {
            root   /var/www/html/cc;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
[root@localhost conf]# nginx -t
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 

檢查測試:

Nginx虛擬主機配置實例

Nginx虛擬主機配置實例

總結(jié)

本文主要是通過Nginx手工編譯安裝的基礎(chǔ)上對Nginx的虛擬主機的相關(guān)配置,分別對應(yīng)的是基于不同域名、不同端口和不同ip進行的相關(guān)配置。重要的是對Nginx的配置文件nginx.conf的配置。這里的域名解析的相關(guān)配置需要比較嫻熟。

下一篇我們將介紹LNMP架構(gòu)的搭建過程

標(biāo)題名稱:Nginx虛擬主機配置實例
分享鏈接:http://jinyejixie.com/article44/ppephe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、虛擬主機、網(wǎng)站內(nèi)鏈、網(wǎng)站維護、企業(yè)網(wǎng)站制作企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營
攀枝花市| 类乌齐县| 巴中市| 西林县| 雅安市| 武陟县| 缙云县| 香港| 揭东县| 喜德县| 枣庄市| 宿迁市| 永寿县| 闸北区| 马龙县| 吉林省| 新兴县| 南川市| 合肥市| 利津县| 安顺市| 弥渡县| 唐山市| 四平市| 岱山县| 霞浦县| 长兴县| 射阳县| 庄河市| 德惠市| 贺兰县| 大名县| 盐津县| 济南市| 双江| 读书| 甘德县| 钟祥市| 吉林省| 贵阳市| 阜宁县|