Jump to realize domain

一、www.a.com -> www.b.com

1 , target: when the input in the page www.a.com time, automatically jump to www.b.com .

2 , the steps:    

(1)  installation of nginx , ensure nginx can be accessed

(2)  modify nginx configuration file

(3)  Restart nginx Service

(4) Browser Test

3, operating procedures

Turn off the firewall and linux security

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0

 

In nginx case of normal access, modify configuration files

 

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
if ($host = "www.b.com") {
        rewrite ^(.*)$ http://www.a.com/$1 permanent;
 }

 

Test grammar, restart

[root@localhost ~]# 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: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Page testing (access www.b.com, return www.a.com)

 

 

 

二、www.a.com/a.html -> www.a.com/file/a.html

1, target: when the input in the page www.a.com/a.html time, automatically jump to www.a.com/file/a.html

2, the steps:

(1)  installation of nginx , can ensure normal access

(2)  modify nginx configuration file

(3)  Restart nginx Service

(4)  in / usr / local / nginx / html create file a.html , write content " 1111111111 "

(5)  in / usr / local / nginx / html create folder file , the file creation file a.html , write the contents of " 22222222 "

(6)  Browser Test

3, the operation

Turn off the firewall and linux security

 

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0

 

 

 

nginx installation finished, modify the configuration file

 

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
location /a.html {
        rewrite ^(.*)$ http://www.a.com/file/a.html permanent;

}

 

Restart nginx Service

[root@localhost ~]# 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: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

Create a file a.html, write the contents of "11111111"

[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# vim a.html
1111111111

Create a file folder, create a file in the file a.html, the preparation of the content "22222222"

[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# mkdir file
[root@localhost html]# ls
50x.html  file  index.html
[root@localhost html]# cd file/
[root@localhost file]# touch a.html
[root@localhost file]# vim a.html
22222222

 Browser Test (access www.a.com/a.html, return www.a.com/file/a.html)

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/tanxiaojuncom/p/11549148.html
Recommended