您好,登錄后才能下訂單哦!
- 基于域名的虛擬主機(jī)
- 基于IP地址的虛擬主機(jī)
- 基于端口的虛擬主機(jī)
[root@localhost ~]# yum install bind -y
[root@localhost ~]# vim /etc/named.conf
options {
listen-on port 53 { any; }; ##監(jiān)聽所有
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 ##配置區(qū)域配置文件
zone "kgc.com" IN {
type master;
file "kgc.com.zone"; ##kgc區(qū)域數(shù)據(jù)配置文件
allow-update { none; };
};
zone "accp.com" IN {
type master;
file "accp.com.zone"; ##accp區(qū)域數(shù)據(jù)配置文件
allow-update { none; };
};
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -p named.localhost kgc.com.zone ##復(fù)制模板
[root@localhost named]# vim kgc.com.zone ##修改區(qū)域配置文件
$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 ##本機(jī)地址
[root@localhost named]# cp -p kgc.com.zone accp.com.zone ##復(fù)制文件為accp區(qū)域數(shù)據(jù)配置文件
[root@localhost named]# systemctl start named ##開啟dns服務(wù)
[root@localhost named]# systemctl stop firewalld.service ##關(guān)閉防火墻
[root@localhost named]# setenforce 0
[root@localhost ~]# mkdir -p /var/www/html/accp ##創(chuàng)建accp站點
[root@localhost ~]# mkdir -p /var/www/html/kgc ##創(chuàng)建kgc站點
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
accp kgc
[root@localhost html]# echo "this a accp web" > accp/index.html ##創(chuàng)建首頁內(nèi)容
[root@localhost html]# echo "this a kgc web" > kgc/index.html ##創(chuàng)建首頁內(nèi)容
[root@localhost ~]# smbclient -L //192.168.100.3/ ##遠(yuǎn)程共享訪問
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 //數(shù)據(jù)壓縮用的函式庫
[root@localhost opt]# useradd -M -s /sbin/nologin nginx ##創(chuàng)建程序用戶,安全不可登陸狀態(tài)
[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 ##狀態(tài)統(tǒng)計模塊
[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/
##創(chuàng)建軟連接讓系統(tǒng)識別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已經(jīng)開啟
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 39620/nginx: master
[root@localhost nginx]# systemctl stop firewalld.service ##關(guān)閉防火墻
[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" ##設(shè)置變量為nginx命令文件
PIDF="/usr/local/nginx/logs/nginx.pid" ##設(shè)置變量PID文件 進(jìn)程號為5346
case "$1" in
start)
$PROG ##開啟服務(wù)
;;
stop)
kill -s QUIT $(cat $PIDF) ##關(guān)閉服務(wù)
;;
restart) ##重啟服務(wù)
$0 stop
$0 start
;;
reload) ##重載服務(wù)
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 ##給啟動腳本執(zhí)行權(quán)限
[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 ##創(chuàng)建配置文件
[Unit]
Description=nginx ##描述
After=network.target ##描述服務(wù)類型
[Service]
Type=forking ##后臺運行形式
PIDFile=/usr/local/nginx/logs/nginx.pid ##PID文件位置
ExecStart=/usr/local/nginx/sbin/nginx ##啟動服務(wù)
ExecReload=/usr/bin/kill -s HUP $MAINPID ##根據(jù)PID重載配置
ExecStop=/usr/bin/kill -s QUIT $MAINPID ##根據(jù)PID終止進(jìn)程
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost ~]# chmod 754 /lib/systemd/system/nginx.service ##設(shè)置執(zhí)行權(quán)限
[root@localhost ~]# systemctl stop nginx.service ##關(guān)閉
[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網(wǎng)站
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網(wǎng)站
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服務(wù)
[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; ##修改監(jiān)聽端口為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 ##創(chuàng)建站點目錄
[root@localhost html]# cd accp8080/
[root@localhost accp8080]# echo "this is accp8080 web" > index.html ##創(chuàng)建首頁內(nèi)容
[root@localhost accp8080]# service nginx restart ##重啟Nginx服務(wù)
192.168.13.138
192.168.13.133
[root@localhost ~]# cd var/named/
[root@localhost named]# vim kgc.com.zone ##修改kgc的區(qū)域數(shù)據(jù)配置文件
$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的區(qū)域數(shù)據(jù)配置文件
$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服務(wù)
[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服務(wù)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。