How to preserve request url with nginx proxy_pass
I think the proxy_set_header
directive could help:
location / {
proxy_pass http://my_app_upstream;
proxy_set_header Host $host;
# ...
}
How to preserve request url with nginx proxy_pass on Mac OSX
If you don't want the URL to change (e.g., due to Nginx pass_proxy subdirectory without url decoding), you should omit the trailing slash from your proxy_pass
:
-proxy_pass http://my_app_upstream/;
+proxy_pass http://my_app_upstream;
NGINX proxy pass a portion of the request URL
This is really simple:
location /path1/ {
proxy_pass http://localhost:8000/;
proxy_http_version 1.1;
}
Read this Q/A for details.
Update
This solution isn't usable after OP clarifies his question.
If all of the additional paths share common suffix path2
:
location /path1/path2 {
rewrite ^/path1(.*) $1 break; # remove '/path1' URI prefix
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
}
If they aren't, replace location /path1/path2
with location ~ ^/path1/(?:path2a|path2b|path2c)
.
If you need to pass to the backend query arguments that are different from those came with the request, use
set $args query1=some-query;
within the location block.
Nginx reverse proxy destination from request url
Solution:
This is the solution I've found:
location ~ "/go/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(.+)$" {
proxy_pass http://$1:80$2;
sub_filter "" " ";
sub_filter_once off;
sub_filter_types application/json application/x-javascript;
sub_filter '"/flash/' '"/go/$1/flash/';
sub_filter '"/rom/' '"/go/$1/rom/';
}
For example I can use the following url: http://myproxyserver/go/192.168.0.100/
and I get the response from the 192.168.0.100 throw the nginx reverse proxy.
Related Topics
Gem Install Pg Doesn't Work on Osx Lion
How to Add Information to an Exception Message in Ruby
Ruby String to Date Conversion
Error While Installing Nokogiri (1.6.7) on El Capitan
How to Set Up Simple Http Authentication for a Ruby on Rails App on Heroku
Removing All Empty Elements from a Hash/Yaml
How to Get Haml to Work with Rails
In Ruby's Test::Unit::Testcase, How to Override the Initialize Method
How to Pass a Parameter for Gem Installation When I Run Bundle Install
How to Get Readline Support in Irb Using Rvm on Ubuntu 11.10
How to Get the Current Time as 13-Digit Integer in Ruby
Why Does My Ruby 'Ri' Tool Not Return Results in Command Prompt
How to Validate Exits and Aborts in Rspec
Gem.Source_Index Is Deprecated, Use Specification. Should I Re-Install Gem or Rails