亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Nginx虛擬主機配置實例

發布時間:2020-06-27 12:19:09 來源:網絡 閱讀:337 作者:wx5d8a17c45cb5b 欄目:系統運維

Nginx虛擬主機

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

結合上篇文章的配置進行下面的配置操作(Nginx服務是開啟狀態)

[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.域名解析配置(環境準備)

[root@localhost ~]# yum install -y bind
...//省略部分內容
  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.創建站點

[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.基于不同域名的服務解析設置

[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基于不同端口訪問

繼續根據上面的第四步的配置

[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地址訪問

添加一塊網卡選擇nat模式

我的是192.168.68.150

1.修改區域數據配置文件

[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虛擬主機配置實例

總結

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

下一篇我們將介紹LNMP架構的搭建過程

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

黑水县| 贡山| 定西市| 山阳县| 清水县| 双柏县| 营山县| 滨州市| 抚顺市| 张家港市| 湖南省| 汕头市| 鹿泉市| 根河市| 左权县| 祁阳县| 舒城县| 石楼县| 平罗县| 伊吾县| 聊城市| 博客| 福州市| 兴城市| 呼和浩特市| 漾濞| 张家港市| 阿拉尔市| 汨罗市| 勐海县| 长丰县| 肃北| 武山县| 九寨沟县| 岚皋县| 和林格尔县| 新密市| 德庆县| 上蔡县| 正安县| 上饶县|