Welcome! Log In Create A New Profile

Advanced

set proxy_pass based on uri argument

Posted by bhuntington 
set proxy_pass based on uri argument
October 13, 2011 07:57AM
I'm trying to set a proxy pass based on an argument that is passed to me in the URI. Unfortunately, the proxy pass never gets set because another if statement is called which causes nginx to never set the proxy (sounds like I shouldn't be using an if statement... I guess it causes nginx to not proceed with any other logic). The nginx documentation says to use try_files but I'm not sure how I would go about using that function for this purpose. Can anyone offer me advice? Here's my config:

user nobody;
worker_processes 8;
worker_rlimit_nofile 8192;
events
{
worker_connections 4096;
}
http
{
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 0;
access_log off;
root html;
log_format getFooBar_ref '[$time_local] ' '"$request" ' '"$http_referer"';
upstream upstream1
{
server 192.168.1.1:8080;
}
upstream upstream2
{
server 192.168.1.2:8080;
}
upstream upstream3
{
server 192.168.1.3:8080;
}
server
{
listen 80 default;
# HERE'S WHERE IT GETS TRICKY
location /getFooBar
{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header HTTP_REFERER $http_referer;
proxy_connect_timeout 1100ms;
proxy_read_timeout 3000ms;
proxy_send_timeout 1000ms;
proxy_pass http://upstream1;
if ($http_referer != ""){
access_log /var/log/nginx/ref/access_getFooBar_ref.log getFooBar_ref;
}
if ($args ~ someParam=1)
{
proxy_pass http://upstream1;
}
if ($args ~ someParam=2)
{
proxy_pass http://upstream2;
}
if ($args ~ someParam=3)
{
proxy_pass http://upstream3;
}
}
}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 281
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