Thursday, 15 April 2010

redirect - Replace image and javascript absolute paths through proxy_redirect in nginx -



redirect - Replace image and javascript absolute paths through proxy_redirect in nginx -

i have scenario follows.

nginx beingness used reverse proxy apache server listening @ port 8080. nginx running @ port 80. there wsgi application beingness run apache server.

now, have added proxy_pass nginx configuration such whatever requests come localhost/ (nginx port default port 80) redirected localhost:8080.

here excerpt nginx conf file:

server { hear 80; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $remote_addr; proxy_set_header host $host; location <app_name> { proxy_pass http://localhost:8080/ proxy_redirect http://localhost/ http://localhost:8080/ } }

i have added proxy redirect take care of redirects apache server request mapping http://localhost/<something> gets redirected http://localhost:8080/<something> because application's resources going available under port 8080.

now, problem here wsgi application generates html image , javascript location paths absolute paths /img/image.png , /js/javascript.js. now, part , parcel of html , not send redirect finish http:// prefix such therefore, server tries locate images in localhost/img directory instead of localhost:8080/img directory.

a dirty workaround same have /img , /js directories defined separate "location" in server config , proxy_pass specified them. these directories more in number , maintaining same potentially become headache.

is there cleaner way of doing this?

this in reference fixing issue in graphite apache cannot serve graphite-web urls other /

in case proxied application (the graphite app in case) isn't able configured "slave" app, improve spare whole subdomain application.

or may seek ngx_http_sub_module which:

…modifies response replacing 1 specified string another.

as illustration code alter ':/localhost:8080/' ':/localhost/app_name/':

location <app_name> { # ... sub_filter ':/localhost:8080/' ':/localhost/app_name/'; }

note that:

this module not built default, should enabled --with-http_sub_module configuration parameter.

but in bundle systems nginx built it's optional modules already. check if version has sub_module built in:

nginx -v | grep sub_module

in case homebrew gives output this.

redirect nginx apache2 reverse-proxy graphite

No comments:

Post a Comment