安装的nginx 地址重写

配置网络源

配置nginx源

安装nginx

启动服务

修改nginx主页

重启访问测试

修改hosts文件

修改主配置文件

server {

        listen    192.168.100.10:80 default_server;

       # listen       [::]:80 default_server;

        server_name  www.newbenet.com;

        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

        location / {

        }

        error_page 404 /404.html;

            location = /40x.html {

        }

        error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        }

    }

    server {

         listen    192.168.100.10:80;

         server_name  www.benet.com;

         location / {

                if ($host = 'www.benet.com') {

                        rewrite ^/(.*)$ http://www.newbenet.com/$1 permanent;

                        }

                }

        }

客户端抓包工具访问测试

旧域名访问

显示结果

旧域名会自动改变成新域名

配置地址带参跳转

正常访问

修改配置文件 禁止访问后台

客户端测试

强制跳转

客户端测试

 

源代码安装的nginx 地址重写

修改主配置文件测试

修改主配置文件配置旧域名访问

server {

        listen    192.168.100.20:80;

        server_name  www.newbenet.com;

        location / {

            root   html;

            index  index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

    }

        server {

        listen 192.168.100.20:80;

        server_name www.benet.com;

        location / {

                if ($host = 'www.benet.com') {

                        rewrite ^/(.*)$ http://www.newbenet.com/$1 permanent;

                        }

                }

 

}

客户端测试

抓包工具测试

配置带参数跳转

创建网站根目录 前后台页面

修改主配置文件

配置hosts文件测试访问

客户端访问后台测试 http://www.benet.com/test.html

禁止访问后台

 server {

        listen     192.168.100.20:80;

        server_name  www.benet.com;

        location / {

            root   /var/www/;

            index  index.html index.htm;

            if ( $request_uri ~ ^/test.html$ ){

                rewrite (.*) http://www.benet.com permanent;

                }

        }

客户端测试 http://www.benet.com/test.html

访问特定网站根目录数据执行跳转

网站根目录创建测试数据

测试正常访问

修改nginx主配置文件访问特定目录数据执行跳转

      location / {

            root   /var/www/;

            location ~* /upload/.*\.php$ {

            rewrite (.+) http://www.benet.com permanent;

                }

访问测试

http://www.benet.com/upload

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值