Score:0

How can I port an Apache RewriteCond and RewriteRule to ngnix?

cn flag

I have to convert an Apache reverse-proxy configuration that uses RewriteCond and RewriteRule, to Nginx.

How can I convert something like this to nginx configuration?

(this is in the main/only <VirtualHost *:443> block)

    RewriteCond %{HTTP_HOST} ^stagingapi$ [NC]
    RewriteRule ^/(.*) https://staging-zone.mydomain.com/$1 [R,L]

Score:0
cn flag

The RewriteRule has as first parameter regular expression which is matching all URI starting with / and as second parameter a substitution, which redirects "stagingapi" site (R flag) to https://staging-zone.mydomain.com/

Try with something like:

server{
  listen 443;
  server_name stagingapi;
  return 301 $scheme://staging-zone.mydomain.com$request_uri permanent;
}

You can replace $scheme with https if you want to redirect all the time to HTTPS to have the same behavior as in apache.

Robert Campbell avatar
cn flag
Thanks Mircea that helped alot.
cn flag
You are welcome!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.