Posted about 5 years ago. Visible to the public.

Reverse-proxying web applications with nginx

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.

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

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

    Copy
    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)

    Copy
    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.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Arne Hartherz
Last edit:
over 4 years ago
by Emanuel De
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more