Proxy + rewrite

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/ goes
https://srvabc:1234/mypath/connexion.do?action=init

and on my NGINX server:

https://www.mynxinx/abc goes
https://www.mynxinx/abc/connexion.do?action=init

What is not working is to have https://www.mynxinx/def going on another
server like 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?

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

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:

http://wiki.nginx.org/HttpMapModule

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

Regards,
Cliff

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs