您好,登錄后才能下訂單哦!
●基于域名的虛擬主機
●基于IP的虛擬主機
●基于端口的虛擬主機
每一種虛擬主機均可通過“server{}" 配置段實現各自的功能
1.基礎源碼包(無密碼):https://pan.baidu.com/s/14WvcmNMC6CFX1SnjHxE7JQ 2.CentOS 7版本Linux虛擬機 |
主機IP | 域名 |
---|---|---|
192.168.235.158 | www.kgc.com,www.accp.com |
第一步:遠程獲取Windows上的源碼包,并掛載到Linux上
[root@localhost ~]# smbclient -L //192.168.235.1
Enter SAMBA\root's password:
Sharename Type Comment
--------- ---- -------
LNMP Disk
[root@localhost ~]# mkdir /abc
[root@localhost ~]# mount.cifs //192.168.235.1/LNMP /abc
Password for root@//192.168.235.1/LNMP:
[root@localhost ~]# ls /abc
Discuz_X3.4_SC_UTF8.zip nginx-1.12.0.tar.gz php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.20.tar.gz
第二步:解壓源碼包
[root@localhost ~]# cd /abc
[root@localhost abc]# tar zxvf nginx-1.12.0.tar.gz -C /opt
[root@localhost abc]# ls /opt
nginx-1.12.0 rh
第三步:下載安裝編譯組件包
[root@localhost abc]# cd /opt
[root@localhost opt]# yum install -y \
> gcc \ //C語言
> gcc-c++ \ //c++語言
> pcre-devel \ //pcre語言工具
> zlib-devel //壓縮函數庫
第四步:創建程序用戶并配置Nginx服務相關組件
[root@localhost opt]# useradd -M -s /sbin/nologin nginx
//創建程序用戶nginx,并限定其不可登錄終端
[root@localhost opt]# cd nginx-1.12.0/
[root@localhost nginx-1.12.0]# ./configure \
//配置nginx
> --prefix=//usr/local/nginx \
//指定安裝路徑
> --user=nginx \
//指定用戶名
> --group=nginx \
//指定用戶所屬組
> --with-http_stub_status_module
//安裝狀態統計模塊
第五步:編譯與安裝Nginx
[root@localhost nginx-1.12.0]# make && make install
第六步:優化Nginx服務啟動腳本,并建立命令軟連接
[root@localhost nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
//創建nginx服務命令軟鏈接到系統命令
[root@localhost nginx-1.12.0]# systemctl stop firewalld.service
//關閉防火墻
[root@localhost nginx-1.12.0]# setenforce 0
//關閉增強型安全功能
[root@localhost nginx-1.12.0]# nginx
//輸入nginx 開啟服務
[root@localhost nginx-1.12.0]# netstat -ntap | grep 80 //查看服務的80 端口,顯示已開啟
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7520/nginx: master
[root@localhost ~]# yum -y install bind
//安裝DNS服務的bind包
[root@localhost ~]# vim /etc/named.conf
//編輯主配置文件
options {
listen-on port 53 { any; };
##將監聽地址127.0.0.1替換為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; };
##將授權localhost替換為any
[root@localhost ~]# vim /etc/named.rfc1912.zones
//編輯兩個域名的區域配置文件
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
zone "accp.com" IN {
type master;
file "accp.com.zone";
allow-update { none; };
};
[root@localhost ~]# cd /var/named
[root@localhost named]# cp -p named.localhost kgc.com.zone
[root@localhost named]# cp -p named.localhost accp.com.zone
[root@localhost named]# vim kgc.com.zone
//編輯kgc域名區域數據配置文件
$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.235.158
##刪除原來末行的內容,添加域名解析地址為本機地址
[root@localhost named]# vim accp.com.zone
//編輯accp域名區域數據配置文件
$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.235.158
##刪除原來末行的內容,添加域名解析地址為本機地址
[root@localhost named]# systemctl start named
//開啟dns服務
[root@localhost named]# systemctl stop firewalld.service
//關閉防火墻
[root@localhost named]# setenforce 0
//關閉增強型安全功能
第一步:創建測試網頁
[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
第二步:編輯nginx.conf配置文件
[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.kgc.com;
charset utf-8;
##支持中文字符
access_log logs/www.kgc.com.access.log;
##kgc站點訪問日志
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;
}
}
第三步:重載Nginx服務
[root@localhost ~]# killall -s HUP nginx
[root@localhost ~]# netstat -ntap | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6117/nginx: master
第四步:測試網頁,輸入www.kgc.com與www.accp.com兩個域名進行訪問
第一步:創建另一個端口的測試網頁
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# echo "this is kgc 8080 web" > kgc/index.html
第二步:編輯nginx.conf配置文件,僅修改監聽地址
[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.235.158:80;
##監聽主機的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.235.158:8080;
##監聽主機的8080端口
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;
}
}
第三步:重載Nginx服務
[root@localhost html]# killall -s HUP nginx
[root@localhost html]# netstat -ntap | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 41958/nginx: master
第四步:測試網頁,分別訪問80端口的默認網頁以及8080端口的網頁
主機IP | 域名 |
---|---|
192.168.235.158 | www.kgc.com |
192.168.235.142 | www.accp.com |
[root@localhost ~]# vim /var/named/accp.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.235.142
##更改IP地址為 192.168.235.142
[root@localhost ~]# systemctl restart named
##重啟域名解析服務
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
##此段不做修改
server {
listen 192.168.235.158: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.235.142:80;
##修改本段監聽地址為192.168.234.142
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;
}
}
[root@localhost ~]# killall -s HUP nginx
[root@localhost ~]# netstat -ntap | grep 80
tcp 0 0 192.168.235.142:80 0.0.0.0:* LISTEN 7299/nginx: master
tcp 0 0 192.168.235.158:80 0.0.0.0:* LISTEN 7299/nginx: master
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。