zoukankan      html  css  js  c++  java
  • 实现域名跳转

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

    1、目标:当在网页中输入www.a.com时,自动跳转到www.b.com

    2、操作步骤:    

    (1) 安装nginx,保证nginx能够正常访问

    (2) 修改nginx的配置文件

    (3) 重启nginx服务

    (4) 浏览器测试

    3、操作流程

    关闭防火墙以及linux安全机制

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

    nginx正常访问的情况下,修改配置文件

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

    测试语法,重启

    [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)

    网页测试(访问www.b.com ,返回www.a.com)

     

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

    1、目标:当在网页中输入www.a.com/a.html时,自动跳转到www.a.com/file/a.html

    2、操作步骤:

    (1) 安装nginx,保证能正常访问

    (2) 修改nginx的配置文件

    (3) 重启nginx服务

    (4) /usr/local/nginx/html下创建文件a.html,编写内容“1111111111

    (5) /usr/local/nginx/html下创建文件夹file,在file下创建文件a.html,编写内容“22222222

    (6) 浏览器测试

    3、操作过程

    关闭防火墙以及linux安全机制

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

    nginx安装完了,修改配置文件

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

    重启nginx服务

    [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()

    创建文件a.html,编写内容“11111111”

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

    创建文件夹file,在file中创建文件a.html,编写内容“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

     浏览器测试(访问www.a.com/a.html ,返回www.a.com/file/a.html)

     

     

  • 相关阅读:
    opengl学习
    同步、异步、多线程与事件型综述
    Javascript异步编程的4种方法
    ASP.NET(C#) GridView (编辑、删除、更新、取消)
    浅析五大ASP.NET数据控件
    用 Eclipse 开发 Android 应用程序
    [C# 网络编程系列]专题十:实现简单的邮件收发器
    [C# 网络编程系列]专题九:实现类似QQ的即时通信程序
    [C# 网络编程系列]专题七:UDP编程补充——UDP广播程序的实现
    [C# 网络编程系列]专题六:UDP编程
  • 原文地址:https://www.cnblogs.com/tanxiaojuncom/p/11549148.html
Copyright © 2011-2022 走看看