需求: 将 http://aaaa.51cto.com/ninnycalf/works 跳转到 http://ninnycalf.51cto.com/works

nginx配置信息如下:

location / {
     rewrite  ^/([a-zA-Z]+)/(.*)$ http://$1.51cto.com/$2 permanent;
}

需求更改,域名保持不变,内容显示为:http://ninnycalf.51cto.com/works 需要使用的nginx的proxy,配置如下:

        #静态文件代理
        location ~ /static/([a-z]+)/(.*)$ {
                proxy_pass http://realserver/static/$1/$2;
                proxy_set_header Host host.51cto.com;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
				
        location ~ ^/([a-zA-Z]+)/(.*)$ {
           proxy_pass http://realserver/$2;
           proxy_set_header Host $1.51cto.com;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }