您好,登錄后才能下訂單哦!
結合上篇文章:手工編譯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
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命令測試是否正常解析
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
[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.不同域名的測試
繼續根據上面的第四步的配置
[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
檢測:
添加一塊網卡選擇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
查看解析是否成功:
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的虛擬主機的相關配置,分別對應的是基于不同域名、不同端口和不同ip進行的相關配置。重要的是對Nginx的配置文件nginx.conf的配置。這里的域名解析的相關配置需要比較嫻熟。
下一篇我們將介紹LNMP架構的搭建過程
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。