# Proxy + rewrite

**URL:** <https://www.ruby-forum.com/t/proxy-rewrite/217591>\
**Category:** NGINX\
**Created:** [March 5, 2012, 11:46pm UTC](https://www.ruby-forum.com/t/proxy-rewrite/217591 "2012-03-05T23:46:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 5, 2012, 11:46pm UTC](https://www.ruby-forum.com/t/proxy-rewrite/217591/1 "2012-03-05T23:46:09Z")

</div>

Hi all,

I’m new with NGINX. What I want to do is a front reverse proxy server  
that rewrites URL.

I actually can make it working with one site, but not with many sites.

On my real server:

[https://srvabc:1234/mypath/](https://srvabc:1234/mypath/) goes  
[https://srvabc:1234/mypath/connexion.do?action=init](https://srvabc:1234/mypath/connexion.do?action=init)

and on my NGINX server:

[https://www.mynxinx/abc](https://www.mynxinx/abc) goes  
[https://www.mynxinx/abc/connexion.do?action=init](https://www.mynxinx/abc/connexion.do?action=init)

What is not working is to have [https://www.mynxinx/def](https://www.mynxinx/def) going on another  
server like [https://srvdef:4567/anothermypath/](https://srvdef:4567/anothermypath/)

I tried many configurations and the most simple one seems to be the one  
using the request\_uri without the / at the beginning (I also tried  
directly with proxy\_pass https:/$request\_uri;):

upstream abc {  
server srvabc:1234 weight=10 max\_fails=3 fail\_timeout=30s;  
}

upstream def {  
server srvdef:4567 weight=10 max\_fails=3 fail\_timeout=30s;  
}

server {  
listen 443 ssl;  
server\_name mynxinx;

```
ssl on;
ssl_certificate /etc/nginx/cert.pem;
ssl_certificate_key /etc/nginx/cert.key;

ssl_session_timeout 5m;

ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location / {

```

if ($request\_uri ~\* ^/(.\*)$) {  
set $request\_key $1;  
}

rewrite /abc /mypath;  
rewrite /def /anothermypath;

proxy\_pass https://$request\_key;  
proxy\_redirect off;

```
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

```

}  
}

What’s wrong my my configuration?

---

<div class="post-metadata">

**Author:** ![alexamat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alexamat](https://www.ruby-forum.com/u/alexamat)\
**Post date:** [March 6, 2012, 12:30am UTC](https://www.ruby-forum.com/t/proxy-rewrite/217591/2 "2012-03-06T00:30:09Z")

</div>

On 03/05/2012 02:46 PM, Alex A. wrote:

> [https://srvabc:1234/mypath/](https://srvabc:1234/mypath/) goes  
> I tried many configurations and the most simple one seems to be the one
> 
> ```
> ssl_protocols SSLv2 SSLv3 TLSv1;
> 
> ```
> 
> rewrite /abc /mypath;  
> }
> 
> What’s wrong my my configuration?

Instead of this way, consider using the map directive:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

The example in the synopsis seems very similar to what you are trying to  
achieve.

Regards,  
Cliff
