作者:重庆垚东科技有限公司 | 来源:互联网 | 2023-05-30 13:54
需求(以sina.com为例):http://abc.sina.com 到 http://www.sina.com/blog/abchttp://abc.sina.com/pics 到 http:
需求(以sina.com为例):
http://abc.sina.com 到 http://www.sina.com/blog/abc
http://abc.sina.com/pics 到 http://www.sina.com/blog/abc/pics
网址要隐式的,地址栏显示 http://abc.sina.com/pics
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| server{
listen 80; ## listen for ipv4; this line is default and implied
server_name sina.com www.sina.com *.sina.com;
set $subdomain '';
if ( $host ~* (\b(?!www\b)\w+)\.sina\.com ) {
set $subdomain $1;
set $suburl $request_uri;
}
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://sina.com;
if ( $suburl ~ "/$" ) {
rewrite ^/(.*) /blog/$subdomain break;
}
root /var/www/sina.com/;
uwsgi_pass 127.0.0.1:8082;
include uwsgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
root /var/www/sina.com/;
access_log off;
expires 30d;
break;
}
} |