Read more

Reverse-proxying web applications with nginx

Arne Hartherz
October 30, 2015Software engineer at makandra GmbH

While you can use Apache as a reverse proxy, it tries to be too smart. Try nginx instead, it's much simpler to set up.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

After struggling with Apache for quite a while, since I simply could not make it pass through the Digest Authentication of my target host (that I proxied to), I switched to nginx. Here is what I did.

  1. Have nginx

    sudo apt-get install nginx
    
  2. Define your nginx config, e.g. at /etc/nginx/conf.d/reverse-proxy.conf:

    server {
      listen 127.0.0.1;
      
      location /foo/ {
        proxy_pass https://www.example.com/;
      }
    }
    
  3. Reload your config (if it fails run sudo nginx -t to debug)

    sudo service nginx reload
    
  4. Done. Visit http://localhost/foo/ and you'll see results of https://www.example.com/.

Note that nginx handles HTTPS out of the box.
Also, should the target host require some kind of HTTP Authentication, it will simply work as nginx passes along all requests (there are multiple for Digest Auth).

Full disclosure: I did not have to rewrite cookies (as shown in the Apache Reverse Proxy guide) in my case, but I assume nginx supports that. Update this card if you know how, or drop us a line.

Posted by Arne Hartherz to makandra dev (2015-10-30 15:23)