rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx bind -y
vim /etc/named.conf
vim /etc/named.rfc1912.zones ##複製添加一段 zone "accp.com" IN { type master; file "accp.com.zone"; allow-update { none; }; };
cd /var/named cp -p named.localhost accp.con.zone vim accp.con.zone
vim /etc/nginx/conf.d/default.conf
systemctl stop firewalld.service setenforce 0 systemctl start named systemctl start nginx
vim /etc/nginx/conf.d/default.conf //添加一段 if ($host = 'www.accp.com') { rewrite ^/(.*)$ http://www.newaccp.com/$1 permanent; } //域名重定向:就是當訪問www.wang.com時,將激動跳轉到www.new.wang.com域名。 //permanent:表示永久的意思。
vim /etc/named.rfc1912.zones //複製以前的accp域名聲明段修改
cd /var/named cp -p accp.com.zone newaccp.com.zone
systemctl stop nginx systemctl start nginx systemctl restart named
vim /etc/nginx/conf.d/default.conf listen 80; server_name www.accp.coom; #charset koi8-r; access_log /var/log/nginx/www.accp.com-access.log main; #設置是否合法的IP標誌 set $rewrite true; #判斷是否爲合法IP if ($remote_addr = "192.168.111.146"){ set $rewrite false; } #非法IP進行判斷打上標記 if ($rewrite = true){ rewrite (.+) /main.html; } #匹配標記進行跳轉站點 location = /main.html { root /usr/share/nginx/html; } systemctl stop nginx systemctl start nginx
cd /usr/share/nginx/html vim main.html <html> <head> <meta charset="utf-8"> <title>test網站</title> </head> <body> <h1>網站維護中,請稍等~~~</h1> </body> </html> systemctl restart nginx
vim /etc/nginx/conf.d/default.conf listen 80; server_name bbs.accp.coom; #charset koi8-r; access_log /var/log/nginx/www.accp.com-access.log; #添加一段 location /post { rewrite (.+) http://www.accp.com/bbs$1 permanent; }
cd /var/named vim accp.com.zone #把裏面的 www 換成 bbs 否則沒法解析。 systemctl restart nginx systemctl restart named echo "nameserver 192.168.111.145" > /etc/resolv.conf
listen 80; server_name www.accp.coom; #charset koi8-r; access_log /var/log/nginx/www.accp.com-access.log main; ## 添加一段 if ($request_uri ~ ^/100-(100|200)-(\d+).html$) { rewrite (.*) http://www.accp.com permanent; }
server_name www.accp.com;
if ($request_uri ~ ^/100-(100|200)-(\d+).html$) {
rewrite (.*) http://www.test.com permanent;
}
123456php
cd /var/named vim accp.com.zone systemctl restart nginx systemctl restart named
vim /etc/nginx/conf.d/default.conf listen 80; server_name www.accp.coom; #charset koi8-r; access_log /var/log/nginx/www.accp.com-access.log main; ## 添加 location ~* /upload/.*\.php$ { rewrite (.+) http://www.accp.com permanent; }
systemctl restart nginx