您好,登錄后才能下訂單哦!
- 基于域名的虛擬主機
- 基于IP地址的虛擬主機
- 基于端口的虛擬主機
[root@localhost ~]# yum install bind -y
[root@localhost ~]# vim /etc/named.conf
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 ##配置區域配置文件
zone "kgc.com" IN {
type master;
file "kgc.com.zone"; ##kgc區域數據配置文件
allow-update { none; };
};
zone "accp.com" IN {
type master;
file "accp.com.zone"; ##accp區域數據配置文件
allow-update { none; };
};
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -p named.localhost kgc.com.zone ##復制模板
[root@localhost named]# vim kgc.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.13.128 ##本機地址
[root@localhost named]# cp -p kgc.com.zone accp.com.zone ##復制文件為accp區域數據配置文件
[root@localhost named]# systemctl start named ##開啟dns服務
[root@localhost named]# systemctl stop firewalld.service ##關閉防火墻
[root@localhost named]# setenforce 0
[root@localhost ~]# mkdir -p /var/www/html/accp ##創建accp站點
[root@localhost ~]# mkdir -p /var/www/html/kgc ##創建kgc站點
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
accp kgc
[root@localhost html]# echo "this a accp web" > accp/index.html ##創建首頁內容
[root@localhost html]# echo "this a kgc web" > kgc/index.html ##創建首頁內容
[root@localhost ~]# smbclient -L //192.168.100.3/ ##遠程共享訪問
Enter SAMBA\root's password:
Sharename Type Comment
--------- ---- -------
LNMP-C7 Disk
[root@localhost ~]# mount.cifs //192.168.100.3/LNMP-C7 /mnt ##掛載到/mnt目錄下
[root@localhost ~]# cd /mnt ##切換到掛載點目錄
[root@localhost mnt]# ls
Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz
mysql-boost-5.7.20.tar.gz php-7.1.20.tar.gz
[root@localhost mnt]# tar zxvf nginx-1.12.2.tar.gz -C /opt ##解壓Nginx源碼包到/opt下
[root@localhost mnt]# cd /opt/ ##切換到解壓的目錄下
[root@localhost opt]# ls
nginx-1.12.2 rh
[root@localhost opt]# yum -y install \
gcc \ //c語言
gcc-c++ \ //c++語言
pcre-devel \ //pcre語言工具
zlib-devel //數據壓縮用的函式庫
[root@localhost opt]# useradd -M -s /sbin/nologin nginx ##創建程序用戶,安全不可登陸狀態
[root@localhost opt]# id nginx
uid=1001(nginx) gid=1001(nginx) 組=1001(nginx)
[root@localhost opt]# cd nginx-1.12.0/ ##切換到nginx目錄下
[root@localhost nginx-1.12.0]# ./configure \ ##配置nginx
> --prefix=/usr/local/nginx \ ##安裝路徑
> --user=nginx \ ##用戶名
> --group=nginx \ ##用戶組
> --with-http_stub_status_module ##狀態統計模塊
[root@localhost nginx-1.12.0]# make ##編譯
...
[root@localhost nginx-1.12.0]# make install ##安裝
...
[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
##創建軟連接讓系統識別nginx啟動腳本
[root@localhost nginx]# 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 nginx]# nginx ##開啟ngnix
[root@localhost nginx]# netstat -ntap | grep 80 ##查看端口,nginx已經開啟
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 39620/nginx: master
[root@localhost nginx]# systemctl stop firewalld.service ##關閉防火墻
[root@localhost nginx]# setenforce 0
[root@localhost nginx]# nginx ##開啟
[root@localhost nginx]# cd /etc/init.d/ ##切換到啟動配置文件目錄
[root@localhost init.d]# ls
functions netconsole network README
[root@localhost init.d]# vim nginx ##編輯啟動腳本文件
#!/bin/bash
# chkconfig: - 99 20 ##注釋信息
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx" ##設置變量為nginx命令文件
PIDF="/usr/local/nginx/logs/nginx.pid" ##設置變量PID文件 進程號為5346
case "$1" in
start)
$PROG ##開啟服務
;;
stop)
kill -s QUIT $(cat $PIDF) ##關閉服務
;;
restart) ##重啟服務
$0 stop
$0 start
;;
reload) ##重載服務
kill -s HUP $(cat $PIDF)
;;
*) ##錯誤輸入提示
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx ##給啟動腳本執行權限
[root@localhost init.d]# chkconfig --add nginx ##添加到service管理器中
[root@localhost init.d]# service nginx stop ##就可以使用service控制nginx
[root@localhost init.d]# service nginx start
[root@localhost ~]# vim /lib/systemd/system/nginx.service ##創建配置文件
[Unit]
Description=nginx ##描述
After=network.target ##描述服務類型
[Service]
Type=forking ##后臺運行形式
PIDFile=/usr/local/nginx/logs/nginx.pid ##PID文件位置
ExecStart=/usr/local/nginx/sbin/nginx ##啟動服務
ExecReload=/usr/bin/kill -s HUP $MAINPID ##根據PID重載配置
ExecStop=/usr/bin/kill -s QUIT $MAINPID ##根據PID終止進程
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost ~]# chmod 754 /lib/systemd/system/nginx.service ##設置執行權限
[root@localhost ~]# systemctl stop nginx.service ##關閉
[root@localhost ~]# systemctl start nginx.service ##開啟
[root@localhost ~]# cd /usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf ##修改Nginx配置文件
server {
listen 80;
server_name www.kgc.com; ##kgc網站
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 80;
server_name www.accp.com; ##accp網站
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 conf]# service nginx restart ##重啟nginx服務
[root@localhost ~]# cd /usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf ##修改Nginx配置文件
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;
}
}
server {
listen 192.168.13.138:8080; ##修改監聽端口為8080
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp8080.com.access.log; ##日志文件修改為8080
location / {
root /var/www/html/accp8080; ##8080端口的站點目錄
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[root@localhost conf]# cd /var/www/html/ ##切換到站點目錄中
[root@localhost html]# mkdir accp8080 ##創建站點目錄
[root@localhost html]# cd accp8080/
[root@localhost accp8080]# echo "this is accp8080 web" > index.html ##創建首頁內容
[root@localhost accp8080]# service nginx restart ##重啟Nginx服務
192.168.13.138
192.168.13.133
[root@localhost ~]# cd var/named/
[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.13.133 ##地址為133
[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.13.138 ##地址為138
[root@localhost named]# systemctl restart named ##重啟dns服務
[root@localhost ~]# cd /usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf ##修改Nginx配置文件
server {
listen 192.168.13.133:80; ##指定IP地址
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.13.138:80; ##指定IP地址
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 conf]# service nginx restart ##重啟Nginx服務
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。