简体   繁体   English

将Apache Port重写为Nginx

[英]port apache rewrite to nginx

I have nginx acting as a reverse proxy to apache. 我让Nginx充当Apache的反向代理。

I have an assets directory with static files that is being served by nginx 我有一个资产目录,其中包含由nginx提供的静态文件

location /assets {
  alias   /var/public/assets;
  expires     1h;
}

However, some of the jpegs served from that directory have a particular format ie 但是,该目录提供的某些jpeg具有特定的格式,即

/assets/test.jpg?p=2&project=wert

I want these urls to be rewritten by nginx so that they are processed by the backend service 我希望这些URL由Nginx重写,以便它们由后端服务处理

I have the below apache rewrite that does what I want 我有下面的Apache重写,可以做我想要的

RewriteEngine On
RewriteCond %{QUERY_STRING} q=[0-9]{1,2}&project=(\w+)$
RewriteRule ^assets/(.*)\.(jpe?g)$ /process/assets/$1.$2 [L]

What is the equivalent for nginx and should I put it in the above location directive or somewhere else? nginx的等效项是什么,我应该将其放在上述location指令中还是其他地方?

Thanks 谢谢

if ($query_string ~ "q=[0-9]{1,2}&project=(\w+)$"){
    rewrite ^/assets/(.*)\.(jpe?g)$ /process/assets/$1.$2 break;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM