中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

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

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

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

保德县| 武清区| 成武县| 海口市| 湘乡市| 许昌市| 修文县| 迁安市| 黄浦区| 寿光市| 葵青区| 沛县| 雅江县| 高唐县| 公安县| 晋中市| 乌海市| 松桃| 合川市| 瑞金市| 马公市| 巴南区| 都安| 宣恩县| 达拉特旗| 英吉沙县| 普陀区| 龙里县| 都江堰市| 法库县| 平陆县| 锡林浩特市| 永定县| 阿尔山市| 永和县| 丘北县| 拜城县| 灵台县| 宁晋县| 麦盖提县| 新田县|