Nginx地址重写以及url重写

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiangshangbashaonian/article/details/82491351

u=2790365501,1930972761&fm=58&bpow=800&bpoh=458.jpg
1、Nginx地址重写
[root@localhost html]# echo aaaaaaa > a.html
[root@localhost html]# echo bbbbbb > b.html

[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf

server {
    listen       80;
    server_name  www.aa.com;
    location / {
        root   html;
        index  index.html index.htm index.php;
        rewrite '/a.html$' /b.html;
    }

[root@localhost nginx]# nginx -s reload
[root@localhost nginx]# firefox www.aa.com/a.html
2、Nginx URL 重写

vim /usr/local/nginx/conf/nginx.conf
...
server {

    listen       80;
    server_name  www.bb.com;
    location / {
        root   www;
        index  index.html index.htm;
        rewrite ^/(.*) http://www.aa.com/bbs/$1;
    }

}
...

[root@localhost nginx]# nginx -s reload
[root@localhost nginx]# firefox www.bb.com

猜你喜欢

转载自blog.csdn.net/xiangshangbashaonian/article/details/82491351