问下nginx配置转发的问题?
我在一个服务器上,配置了伪静态
location / {
index index.html index.htm index.php;
#autoindex on;
try_files $uri $uri/ /index.php$is_args$query_string;
}
然后我想在这个服务器做一个转发。
location /api/newweb{
proxy_pass https://test.com:8080/api/newweb;
break;
}
我想当请求 /api/newweb 开头时候能转发到另一个端口上,这应该怎么配置的呢?
然后不知为什么我加了这个配置后,就不能转发了,我应该怎么既能加上下面的配置又能转发呢?
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
-e $request_filename
表示判断当前请求的路径是否是存在的文件,前面加个!
就是如果当前请求的路径不是真实的文件路径的话,就会走到这个 if 中然后你 if 里面的 rewrite 是把当前路径改成了
/index.php?s=$1
, 比如路径是/api/xxxx
,现在变成了/index.php?s=/api/xxxx
所以你的 location 就失效了
如果
既要又要
的话,可以把!-e $request_filename
写到跟location /api/newweb
相反的 location 块中以上纯个人经验,没查资料,有不对的地方轻喷