Welcome! Log In Create A New Profile

Advanced

Use variable with nginx proxy_pass

Posted by labrouka 
Use variable with nginx proxy_pass
July 29, 2015 03:38AM
Hi,

I'm new on nginx and I want to implement a particular configuration.

I set up a redirect URL http://mydomain.com/images/test/v1/03760089810361_D1C1_s89.jpg
to the URL http://anotherdomain.com/permalink/v1/1/4/preview/03760089810361_D1C1_s89.jpg?token=Ck8fP9xe
All this keeping the first URL.

To do this, I use the following configuration works properly :

server {
listen 80;
access_log /var/log/nginx/test.log;
server_name mydomain.com;
location /images/test/v1/03760089810361_D1C1_s89.jpg {
proxy_pass http://anotherdomain.com/permalink/v1/1/4/preview/03760089810361_D1C1_s89.jpg?token=Ck8fP9xe
}
}

I would like to use variables on the first URL to inject in the second.
So I could have a configuration of this type however, this one does not work :

server {
listen 80;
access_log /var/log/nginx/test.log;
server_name mydomain.com;
location /images/test/$1/$2 {
proxy_pass http://anotherdomain.com/permalink/$1/1/4/preview/$2?token=Ck8fP9xe
}
}

Can you give me the good configuration ?

Regards,
Re: Use variable with nginx proxy_pass
July 29, 2015 10:32AM
OK, I solvez a part of my problem with this configuration:

server {
listen 80;
access_log /var/log/nginx/test.log;
server_name mydomain.com

location /images/ {
rewrite ^(/images.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)$ http://anotherdomain.com/permalink/$2/$3/$4/$5/$7?token=$6 last;
}
}

However, this configuration keep the rewrite ULR but I want to keep the first URL.
How to do ?

Regards,
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 82
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready