Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve request url with nginx proxy_pass

I was trying to use Thin app server and had one issue.

When nginx proxies the request to Thin (or Unicorn) using proxy_pass http://my_app_upstream; the application receives the modified URL sent by nginx (http://my_app_upstream).

What I want is to pass the original URL and the original request from client with no modification as the app relies heavily on it.

The nginx' doc says:

If it is necessary to transmit URI in the unprocessed form then directive proxy_pass should be used without URI part.

But I don't understand how exactly to configure that as the related sample is actually using URI:

location  /some/path/ {   proxy_pass   http://127.0.0.1; } 

So could you please help me figuring out how to preserve the original request URL from the client?

like image 332
Dmytrii Nagirniak Avatar asked Apr 29 '11 15:04

Dmytrii Nagirniak


People also ask

What does proxy_pass do in Nginx?

The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.

What is Nginx proxy redirect?

Nginx (pronounced “Engine-X”) is a Linux-based web server and proxy application. Nginx is a powerful tool for redirecting and managing web traffic. It can be easily configured to redirect unencrypted HTTP web traffic to an encrypted HTTPS server.

How does Nginx reverse proxy work?

A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.


1 Answers

I think the proxy_set_header directive could help:

location / {     proxy_pass http://my_app_upstream;     proxy_set_header Host $host;     # ... } 
like image 186
yibe Avatar answered Sep 24 '22 18:09

yibe