Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference HTTP Redirect vs Reverse Proxy in NGINX

I'm having some difficulty in understanding the difference between reverse proxy (i.e. using proxy_pass directive with a given upstream server) and a 301 permanent redirect. How are they similar/different?

Reverse Proxy

upstream backend {
    server backend1.example.com       weight=5;
    server backend2.example.com:8080;
}

server {
    location / {
        proxy_pass http://backend;
    }
}

HHTP Redirect

Apache Example: http://www.inmotionhosting.com/support/website/htaccess/redirect-without-changing-url

NGINX example:

server {
    listen 80;
    server_name domain1.com;
    return 301 $scheme://domain2.com$request_uri;
}

Hence, it seems that both approaches have no difference from an end-user perspective. I want to ensure efficient bandwidth usage, while utilizing SSL. Currently, the app server uses its own self-signed SSL certificate with Nginx. What is the recommended approach for redirecting users from a website hosted by a standard web hosting company (hostgator, godaddy, etc.) to a separate server app server?

like image 440
cynical biscuit Avatar asked Feb 10 '17 07:02

cynical biscuit


1 Answers

With a redirect the server tells the client to look elsewhere for the resource. The client will be aware of this new location. The new location must be reachable from the client.
A reverse proxy instead forwards the request of the client to some other location itself and sends the response from this location back to the client. This means that the client is not aware of the new location and that the new location does not need to be directly reachable by the client.

like image 99
Steffen Ullrich Avatar answered Sep 25 '22 02:09

Steffen Ullrich