I have server with CORS problems which causes a lot of pain during development phase. Previously while I was using windows it was quite easy with IIS rewrite module. Something like;
<rules>
<rule name="ReverseProxyInboundRule3" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_URL}" pattern="^.*(pattern1|pattern2|pattern3|pattern4).*$" />
</conditions>
<action type="Rewrite" url="https://example.com/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
so say the call in my environment is;
localhost:8080/folder1/folder2/folder3/pattern1?param1=val1¶m2=val2¶m3=val3
request is sent to
https://example.com/pattern1?param1=val1¶m2=val2¶m3=val3
I tried some basic rewrite tricks but unfortunately could not make it work, and not that experinced on nginx's rewrite syntax.
After some trial (some is an optimistic choice of word) I found how to do what I am looking for.
Be carefull that there is no trailing slash either on
location block
orproxy_pass
directive. Also the keywordlast
used at the end of the rewrite directive since I am doing it out oflocation
block