您好,登錄后才能下訂單哦!
公司舊域名www.accp.com ,因業(yè)務(wù)需求有變更,需要使用新域名www.kgc.com 代替
不能廢除舊域名
從舊域名跳轉(zhuǎn)到新域名,且保持其參數(shù)不變
Linux服務(wù)器(192.168.13.144)
測試機(jī)win7
[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
##安裝nginx官方源
警告:/var/tmp/rpm-tmp.vS0k20: 頭V4 RSA/SHA1 Signature, 密鑰 ID 7bd9bf62: NOKEY
準(zhǔn)備中... ################################# [100%]
正在升級(jí)/安裝...
1:nginx-release-centos-7-0.el7.ngx ################################# [100%]
[root@localhost ~]# yum install nginx -y ##yum安裝nginx
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf ##修改默認(rèn)配置文件
server {
listen 80;
server_name www.accp.com; ##修改主機(jī)名
#charset koi8-r;
access_log /var/log/nginx/www.accp.com-access.log main; ##開啟日志服務(wù)
[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 "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 accp.com.zone ##復(fù)制模板
[root@localhost named]# vim accp.com.zone ##修改區(qū)域配置文件
$TTL 1D
@ IN SOA @ rname.invalid. (
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www IN A 192.168.13.144 ##本機(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 named]# systemctl start nginx ##開啟nginx服務(wù)
[root@localhost named]# netstat -ntap | grep nginx ##查看端口
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4093/nginx: master
[root@localhost named]# vim /etc/nginx/conf.d/default.conf ##修改配置文件
server {
listen 80;
server_name www.accp.com;
#charset koi8-r;
access_log /var/log/nginx/www.accp.com-access.log main;
location / {
if ($host = "www.accp.com"){ ##匹配如果域名是老域名
rewrite ^/(.*)$ http://www.kgc.com/$1 permanent; ##則永久設(shè)置跳轉(zhuǎn)新域名
}
root /usr/share/nginx/html;
index index.html index.htm;
}
[root@localhost named]# vim /etc/named.rfc1912.zones
zone "kgc.com" IN {
type master;
file "kgc.com.zone"; ##accp區(qū)域數(shù)據(jù)配置文件
allow-update { none; };
};
[root@localhost named]# cp -p /var/named/accp.com.zone /var/named/kgc.com.zone
##復(fù)制區(qū)域數(shù)據(jù)配置文件為kgc的數(shù)據(jù)配置文件
[root@localhost named]# systemctl restart named ##重啟解析服務(wù)
[root@localhost named]# systemctl restart nginx ##重啟nginx服務(wù)
公司業(yè)務(wù)版本上線,所有IP訪問任何內(nèi)容都顯示一個(gè)固定維護(hù)頁面,只有公司IP訪問正常
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vim default.conf
server {
listen 80;
server_name www.accp.com;
#charset koi8-r;
access_log /var/log/nginx/www.accp.com-access.log main;
#設(shè)置是否合法的IP標(biāo)志
set $rewrite true; ##設(shè)置變量為真
#判斷是否為合法的IP
if ($remote_addr = "192.168.13.140"){
set $rewrite false; ##匹配合法IP,將變量設(shè)置為假,正常跳轉(zhuǎn)頁面
}
#非法IP進(jìn)行判斷打上標(biāo)記
if ($rewrite = true){ ##匹配非法IP,跳轉(zhuǎn)到main的網(wǎng)頁
rewrite (.+) /main.html;
}
#匹配標(biāo)記進(jìn)行跳轉(zhuǎn)站點(diǎn)
location = /main.html { ##精確匹配
root /usr/share/nginx/html; ##站點(diǎn)路徑
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
[root@localhost conf.d]# cd /usr/share/nginx/html/ ##切換到站點(diǎn)中
[root@localhost html]# vim main.html ##編輯非法IP訪問網(wǎng)頁內(nèi)容
<h2>this is test web</h2>
[root@localhost html]# systemctl restart nginx ##重啟Nginx服務(wù)
將域名http://bbs.accp.com 下面的發(fā)帖都跳轉(zhuǎn)到http://www.accp.com/bbs 且域名跳轉(zhuǎn)后保持參數(shù)不變
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vim default.conf ##修改默認(rèn)配置文件
server {
listen 80;
server_name bbs.accp.com; ##修改服務(wù)名稱
#charset koi8-r;
access_log /var/log/nginx/www.accp.com-access.log main;
location /post { ##用location匹配post目錄
rewrite (.+) http://www.accp.com/bbs$1 permanent; ##永久重定向跳轉(zhuǎn)
}
[root@localhost conf.d]# cd /var/named/
[root@localhost named]# vim accp.com.zone ##修改區(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
bbs IN A 192.168.13.144
[root@localhost named]# systemctl restart named ##重啟解析服務(wù)
[root@localhost named]# systemctl restart nginx ##重啟Nginx服務(wù)
[root@localhost named]# echo "nameserver 192.168.13.144" > /etc/resolv.conf
##將解析服務(wù)器地址放到本地解析配置文件中
瀏覽器訪問
http://www.accp.com/100-(100|200)-100.html 跳轉(zhuǎn)到http://www.accp.com 頁面
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vim default.conf
server {
listen 80;
server_name www.accp.com;
#charset koi8-r;
access_log /var/log/nginx/www.accp.com-access.log main;
if ($request_uri ~ ^/100-(100|200)-(\d+).html$){
##匹配正則開頭為100-(100|200)-一次多次的整數(shù)html為結(jié)尾的
rewrite (.*) http://www.accp.com permanent; ##永久重定向跳轉(zhuǎn)到主頁
}
[root@localhost conf.d]# vim /var/named/accp.com.zone ##修改區(qū)域數(shù)據(jù)配置文件
www IN A 192.168.13.144
[root@localhost conf.d]# systemctl restart named ##重啟解析服務(wù)
[root@localhost conf.d]# systemctl restart nginx ##重啟Nginx服務(wù)
訪問http://www.accp.com/upload/1.php 跳轉(zhuǎn)到首頁
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vim default.conf ##修改默認(rèn)配置文件
server {
listen 80;
server_name www.accp.com;
#charset koi8-r;
access_log /var/log/nginx/www.accp.com-access.log main;
location ~* /upload/.*\.php$ { ##匹配不分大小寫,匹配upload后零次或多次以.php為結(jié)尾的
rewrite (.+) http://www.accp.com permanent; ##跳轉(zhuǎn)到首頁
}
[root@localhost conf.d]# systemctl restart nginx ##重啟Nginx服務(wù)
訪問一個(gè)具體的頁面跳轉(zhuǎn)到首頁
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vim default.conf ##修改Nginx默認(rèn)配置文件
server {
listen 80;
server_name www.accp.com;
#charset koi8-r;
access_log /var/log/nginx/www.accp.com-access.log main;
location ~* ^/abc/123.html { ##匹配某一個(gè)特定的網(wǎng)頁
rewrite (.+) http://www.accp.com permanent; ##跳轉(zhuǎn)到首頁
}
[root@localhost conf.d]# systemctl restart nginx ##重啟Nginx服務(wù)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。