本来想做一个,根据访问过来的UA去代理到其他的站点的需求。nignx是非常省心的代码像这样。
server {
listen 89;
server_name localhost ;
location / {
proxy_set_header Host $host:$proxy_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if ($http_user_agent ~* "Baidu") {
proxy_pass http://127.0.0.1:82; #判断UA进行跳转
}
root D:\myWork\pc-vue-web\dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;#404页面都跳转到index
}
location /api {
proxy_pass http://gelonghui.com;
}
}
经过测试是没毛病的
可是换上caddy 之后代码像这样的
127.0.0.1:81 {
root D:\myWork\pc-vue-web\dist
gzip
log ../access.log
ext .html
proxy /api gelonghui.com
errors {
404 /index.html
}
#可能是没知道方法吧比并没有识别出来
rewrite {
if {>User-agent} has Baidu
to proxy / 127.0.0.1:82
}
}
127.0.0.1:82 {
root D:\seo
gzip
log ../access.log
ext .html
}
网友评论