Guys,
The following is what I have done. My goal is ultimately use regex to
inspect the incoming URI and make proxy_pass decisions. The if statement
below is just a test to validate the if statements work. As you can
see, I get the “unkown directive” error. Do you think I need to use the
–with-pcre= option?
yum install gcc openssl-devel pcre-devel zlib-devel
yum install mlocate
./configure --sbin-path=/sbin/nginx
–conf-path=/usr/local/nginx/nginx.conf
–pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module
–with-http_perl_module --without-http_rewrite_module
make
sudo make install
============================= snippet from
nginx.conf=============================
location /johndesp/ {
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_redirect off;
proxy_pass_request_headers on;
if (!-f $request_filename) {
proxy_pass
http://ec2-75-101-166-203.compute-1.amazonaws.com:8080/johndesp/;
}
thanks
johndesp
Posted at Nginx Forum:
Igor,
Thanks. My ultimate goal is to have the flexibility to inspect the
incoming uri and make decisions as to what backend host to send the
request to.
For instance,
I might want
Incoming URI /johndesp/( {1}) ----> proxy_pass
http://host1/johndesp/whatever
Incoming URI /johndesp/([0-9] {1}) ----> proxy_pass
http://host1/johndesp/whenever
example
/johndesp/b ---------------- proxy_pass
http://host1:8080/johndesp/whatever * notice this is not
http://host1:8080/johndesp/whatever/b
likewise I would want the following:
johndesp/5 ---------------- proxy_pass
http://host2:8080/johndesp/whenever * notice this is not
http://host1:8080/johndesp/whatever
I tried to use the following…however, I did not get the desired result:
location “~* ^/johndesp/whatever/( {1}”{
proxy_pass http://host1:8080/johndesp/whatever;
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_redirect off;
}
but I get this error:
: the using of the regex " ^/johndesp/whatever/( {1}" requires PCRE
library in /usr/local/nginx/nginx.conf:43
Posted at Nginx Forum:
On Tue, Nov 24, 2009 at 12:08:10PM -0500, johndesp wrote:
Guys,
The following is what I have done. My goal is ultimately use regex to inspect the incoming URI and make proxy_pass decisions. The if statement below is just a test to validate the if statements work. As you can see, I get the “unkown directive” error. Do you think I need to use the --with-pcre= option?
The “if” directive is in disabled http_rewrite_module.
============================= snippet from nginx.conf=============================
location /johndesp/ {
try_files $uri @amazonaws;
}
location @amazonaws {
proxy_pass
http://ec2-75-101-166-203.compute-1.amazonaws.com:8080/johndesp/;
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_redirect off;
}
–
Igor S.
http://sysoev.ru/en/
Igor,
Does the ‘if’ statement in mod_rewrite have any trouble working with
external modules that are compiled in? I’m seeing that variables used in
external modules are not being set if they’re inside an ‘if’ block. See
my previous message about 12 hours ago with subject “Module vars set
inside if’s are not set” for details.
Mark.
On Tue, Nov 24, 2009 at 01:14:28PM -0500, johndesp wrote:
Incoming URI /johndesp/([0-9] {1}) ----> proxy_pass http://host1/johndesp/whenever
location “~* ^/johndesp/whatever/( {1}”{
proxy_pass http://host1:8080/johndesp/whatever;
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_redirect off;
}
but I get this error:
: the using of the regex " ^/johndesp/whatever/( {1}" requires PCRE library in /usr/local/nginx/nginx.conf:43
If you do not need the rewrite module, but want to use regex in
locations, etc., then you need to
./configure --with-pcre --without-http_rewrite_module
Also, note that you can not use URI part “/johndesp/whatever” in
proxy_pass
if location is given by regex:
location ~* “^/johndesp/whatever/( {1})” {
proxy_pass http://host1:8080/johndesp/whatever;
because nginx does not know what it should replace in original URI.
You may use
location ~* “^/johndesp/whatever/( {1})(.+)$” {
proxy_pass http://host1:8080/johndesp/whatever/$2;
or
location ~* “^/johndesp/whatever/( {1})” {
proxy_pass http://host1:8080;
or
location /johndesp/whatever/ {
proxy_pass http://host1:8080/something/els/;
–
Igor S.
http://sysoev.ru/en/