194

This is likely the most efficient way to do what you want, without the use of any regular expressions: location = /en { return 302 /en/; } location /en/ { proxy_pass http://luscious/; # note the trailing slash here, it matters! }


57

A small addition to the great answer from Xaviar: If you happen to be not so well acquainted with nginx, there's an important difference between adding the slash to the end of the proxy_pass directive. The following does not work: location ~* ^/dir/ { rewrite ^/dir/(.*) /$1 break; proxy_pass http://backend/; but this one does: location ~* ^/dir/ { ...


37

it looks like proxy_http_module isn't getting loaded, make sure you have following inside of your httpd.conf: LoadModule proxy_http_module modules/mod_proxy_http.so


29

The problem is basically that using a proxy_pass directive won't rewrite HTML code and therefor relative URL's to for instance a img src="/assets/image.png" won't magically change to img src="/bbb/assets/image.png". I wrote about potential strategies to address that in Apache httpd here and similar solutions are possible for nginx as well: If you have ...


27

Yes! Above the ProxyPass /, add: ProxyPass /broken/page.html ! That'll force the proxypass to not act on the page that you're trying to redirect.


25

It tells you that the URI in the proxy pass directive can't be used in a regex location. This is because nginx can't replace the part of the URI matching the regex in the location block with the one passed in the proxy_pass directive a generic way. Simply imagine your location regex is /foo/(.*)/bar, and you specify proxy_pass http://server/test, nginx ...


18

proxy_http module requires proxy, and ProxyPass directive is defined in the latter. Make sure it's also loaded.


15

I'd like to address a newer regex-based answer that's been rising in popularity. location ~ ^/en(/?)(.*)$ { # OOPS! proxy_pass http://luscious/$2$is_args$args; # OOPS! } The solution may seem more cute at first glance, but it's wrong for multiple reasons. The above regex would match a request uri of /enjoy, redirecting it to /joy upstream. Is this ...


15

Make sure that the following apache modules are installed and loaded: mod_proxy mod_proxy_http mod_ssl You can check via running the following command as root(assuming httpd is in your $PATH) httpd -t -D DUMP_MODULES Afterwards, try changing your configuration to the following: ProxyRequests Off <Proxy *> Order deny,allow Deny from all ...


10

<Proxy> blocks are also useful as the context is always understood to be applying to proxied traffic. In this fashion you don't need to exclude specific paths. <Proxy *> Redirect permanent /broken/page.html https://www.example.com/correct/page.html RedirectMatch ^/deadstuff.+ http://www.example.com/correct/page.html </Proxy> ...


9

So I think - here is the solution if I understood the problem correctly: # backend.wants.this.server.com # browser.shows.this.server.com server { listen 80; server_name browser.shows.this.server.com; location / { proxy_set_header Host backend.wants.this.server.com; proxy_redirect http://backend.wants.this.server.com/ http://browser.shows....


9

When you are using variables in a proxy_pass directive, nginx will use runtime resolving except if : the target server is declared as an IP address the target server name is part of an upstream server group the target server name has already been resolved (e.g. it matches a server name in another server block) Here, a runtime resolver won't help as ...


9

In the default Apache configuration, the AllowEncodedSlashes directive is set to off. This means that: "...The AllowEncodedSlashes directive allows URLs which contain encoded path separators [...] to be used in the path info. With the default value, Off, such URLs are refused with a 404 (Not found) error. ..." So the problem is that mod_proxy is not ...


8

It may help to set some headers so that the upstream knows the correct frontend server name. See this document for more. For example, I use: proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Accept-Encoding ""; ...


7

Telepathy about port 8080 has been turned off, because you don't show us the full config. server { listen 80; server_name connect3.domain.ru www.connect3.domain.ru; location / { proxy_pass http://connect2.domain.ru; proxy_set_header Host connect2.domain.ru; } }


7

One option is to install mod_proxy_handler: https://gist.github.com/progandy/6ed4eeea60f6277c3e39 Or you can wait for Apache 2.4.10, which should include the module. Basically the module lets you do this: #tcp <FilesMatch \.php$> SetHandler proxy:fcgi://localhost:9000 </FilesMatch> #uds <FilesMatch \.php$> SetHandler "proxy:unix:/...


7

I have established what the problems were with my setup. 1) SELinux was preventing me from connecting upstream. I have now disabled this and will consider setting it up properly later 2) proxy_pass was doing its job as expected, however the args I needed were http://123.123.123.1:$server_port/$uri$is_args$args; 3) proxy_set_header Host $host correctly set ...


6

From nginx's documentation (context : prefixed location) If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive. So it can be simplified with the following : location /jazz/ { proxy_pass http://...


5

So, I found the answer on stackoverflow: upstream luscious { server lixxxx.members.linode.com:9001; } server { root /var/www/example.com/current/public/; server_name example.com; location ~ ^/en(/?)(.*) { proxy_pass http://luscious/$2; } } Basically: passing a regex into location and passing the backref along to the proxy_pass url.


5

If I had to guess, I would say your problem comes from the "^/.*$" match, which will match '/'. If you dropped the explicit match to / and replaced the proxy pass with "^/.+$" is may resolve your issue. No promises though. The difference is the * is equivalent to .{0,} while + is equivalent to .{1,}, so .* will match any or no characters, whereas you want a ...


5

This is easily done with mod_proxy: ProxyPass /rep1/ibm http://reportingserver1.example.com/ibm ProxyPassReverse /rep1/ibm http://reportingserver1.example.com/ibm ProxyPass /rep2/ibm http://reportingserver2.example.com/ibm ProxyPassReverse /rep2/ibm http://reportingserver2.example.com/ibm There is more information at the apache documentation site for ...


5

I've been struggling with this same problem for a few days and I might have cracked it. I'm new to Spring Security so don't take this as gospel! Others might object... I'm using Apache 2.4 (on OS X) and Spring Security 4.1.1. Everything ran perfectly well running locally, but whenever it was deployed to run behind a reverse proxy I got 404 errors every time ...


5

You want to maintain the port, then you should put it in proxy_pass. server { server_name bob.something.com; listen 41001; listen 41002; listen 8080; location / { proxy_pass http://123.123.123.1:$server_port$uri; proxy_set_header Host $host; } } You have to realize that this will proxy request through ...


5

This should works: DocumentRoot /var/www/html Redirect (!/mm) https://server.org/test/ Alias /mm "/var/opt/mm" Alias /test/mm "/var/opt/mm" <Directory "/var/opt/mm"> Options Indexes FollowSymLinks AllowOverride All </Directory> ProxyRequests Off ProxyPreserveHost On ProxyStatus On ProxyPass /test/mm ! ProxyPass /test/ http://...


4

It's an old thread but maybe it will help someone: In addition to answers of Mark Henderson (mod_proxy) OR James Sneeringer (302,301 redirect to new subdomains), one more thing could be added regarding database sync when moving big applications. If your web project uses a database (ex. MySQL), before switching the DNS, make sure the applications (ex. PHP) ...


4

When you use proxy_pass without proxy_set_header directives, nginx will use some default headers. Most times it's what you would want or, at least, harmless, but in your case you have to set them manually. When you write proxy_pass http://w, nginx will set proxy_set_header Host w. If you need another Host header, you should set it explicitly. Most common is ...


4

After searching around the solution is to group the directives under a <Location> tag: <Location /app1> ProxyPassReverseCookiePath /app /app1 </Location> <Location /app2> ProxyPassReverseCookiePath /app /app2 </Location> This way Apache knows to properly apply each directive depending on the origin of the response.


4

As @MichaelHampton already commented: remove the following settings immediately: <Proxy *> order allow,deny deny from 193.37.XXX.XX allow from all </Proxy> Those are not needed for a reverse proxy but instead used to configure a forward proxy , open to almost anybody, which will allow your server to be abused. ( Fortunately you ...


3

EDIT 2 As per VBart's comments, I've changed the entries in try_files to $uri @proxy_to_app. This avoids any confusion over the order of named locations (they must always come last). Be advised that if the /admin/ directory exists locally, this will be used instead of the proxy. EDIT If you really want to use a named location to avoid duplicating ...


Only top voted, non community-wiki answers of a minimum length are eligible