Forum: NGINX lots of work in a location block.

671d9faabfe3d3382be736b93fbfa1d5?d=identicon&s=25 Steve Holdoway (Guest)
on 2014-06-18 02:16
(Received via mailing list)
Hi Folks,

I'm trying to integrate a python backend into a pre-existing php
website, and am having problems doing this as I need to rewrite the url
at the same time... eg: this is what isn't working.

  location = /example {
    rewrite /example/(.*) /$1 break;

    root /www/example;

    include proxy_params;
    proxy_pass http://python;

    #break;
  }
( stripped to bare essentials )

So it's
 - strip off the /example prefix
 - set the new root ( the php site sets is outside any location block )
 - pass stripped request to the python backend.

I've tried every option I can think of, but they all seem to drop out of
the location block and process the rewritten request again, which means
that they're not using the static files in the locally defined root, and
also aren't being handed to the python backend for processing.

I've fudged it for the moment, but would really like to do it properly!

Cheers,

Steve.

Oh, proxy_params contains

proxy_next_upstream error timeout invalid_header http_500 http_502
http_503 http_504;
proxy_redirect off;
proxy_buffering 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;




--
Steve Holdoway BSc(Hons) MIITP
http://www.greengecko.co.nz
Linkedin: http://www.linkedin.com/in/steveholdoway
Skype: sholdowa
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2014-06-18 09:14
(Received via mailing list)
On Wednesday 18 June 2014 12:15:29 Steve Holdoway wrote:
> Hi Folks,
>
> I'm trying to integrate a python backend into a pre-existing php
> website, and am having problems doing this as I need to rewrite the url
> at the same time... eg: this is what isn't working.
>
>   location = /example {

The only request, that will be handled by your location with "="
modifier
is "/example", even "/example/" isn't fit.

>
> So it's
>  - strip off the /example prefix
>  - set the new root ( the php site sets is outside any location block )
>  - pass stripped request to the python backend.
[..]

Please note, that the "root" directive is almost meaningless in location
with "proxy_pass".

And you don't need "rewrite".

Something like that should work:

  location /example/ {
      include proxy_params;
      proxy_pass http://python/;
  }

Please also check the docs:

http://nginx.org/r/proxy_pass
http://nginx.org/r/location

  wbr, Valentin V. Bartenev
671d9faabfe3d3382be736b93fbfa1d5?d=identicon&s=25 Steve Holdoway (Guest)
on 2014-06-18 09:36
(Received via mailing list)
That's a red herring... cut/paste error. The rewrite is being processed,
the result isn't being passed to the proxy server.
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2014-06-18 10:14
(Received via mailing list)
On Wednesday 18 June 2014 19:35:02 Steve Holdoway wrote:
> That's a red herring... cut/paste error. The rewrite is being processed,
> the result isn't being passed to the proxy server.
>
[..]

Without a full and exact copy of your configuration there's no way
to help you.  Every single bit of it has meaning.  You are assuring
us that the configuration is ok, then where is the problem?

  wbr, Valentin V. Bartenev
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.