How do I configure Nginx to be a forward proxy which requires a username and password?

user173847 asked:

Right now I have a proxy set up at, but I’d like to have it secured.

To get this proxy setup I added this to my nginx config file:

server {
    listen       8080;

    location / {
        proxy_pass http://$http_host$uri$is_args$args;

I tried searching but only came up with results for a /reverse/ proxy. I need a regular one.

My answer:

nginx makes a great reverse proxy, but is less than ideal as a forward proxy. It can be done, but since writing the rules you want will be rather hairy, you’re almost certainly better off to use a purpose-built forward proxy, such as squid. Doing so also means your future self will have a much better chance of understanding what’s going on when trying to maintain or debug the proxy.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.