1
回答
求一个nginx个性域名的重写规则
百度AI开发者大赛带你边学边开发,赢100万奖金,加群:418589053   
想法:
http://abc.ccav.com rewrite 到 http://www.ccav.com/uid/abc
http://abc.ccav.com/article/index/index rewrite 到 http://www.ccav.com/article/index/index/uid/abc

http://abc.ccav.com/article/index/show/id/1 rewrite 到 http://www.ccav.com/article/index/show/uid/abc/id/1

http://abc.ccav.com/shop/index/index rewrite 到 http://www.ccav.com/shop/index/index/uid/abc

http://abc.ccav.com/shop/index/show/id/1 rewrite 到 http://www.ccav.com/shop/index/show/uid/abc/id/1

自己实际试了几下,都没成功,求大神指点
举报
离开江湖
发帖于3年前 1回/90阅
共有1个答案 最后回答: 3年前

自己解决了

server {
    listen 80;
    #rewrite_log on;
    #error_log /datas/logs/ccav_rewrite.log notice;
    server_name *.u.ccav.com;
    location ~ ^/(images|styles|scripts|uploads)/
    {
        proxy_redirect        off;
        proxy_set_header    Host   www.ccav.com;
        proxy_pass      http://127.0.0.1:80;
    }
    location / {
        set $uid default;
        if ( $http_host ~* "^(.*)\.u\.ccav\.com") {
            set $uid $1;
        }
        rewrite ^/article/index/show/id/([0-9]+)/?$  /article/index/show/uid/$uid/id/$1 break;
        rewrite ^/article/index/index/?$  /article/index/index/uid/$uid break;
        rewrite ^/article/index/category/cid/([0-9]+)/?$  /article/index/category/uid/$uid/cid/$1 break;
        proxy_pass http://www.ccav.com;
    }
}

顶部