Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have nginx running on simple ubuntu VPS that acts like a simple HTTP proxy:

server {
  listen 8080;
  location / {
    resolver 8.8.8.8;
    proxy_pass http://$http_host$uri$is_args$args;
  }
}

All works fine, but anyone can connect to this proxy :(. Is i any easy way to add some login/password to it? HTTP basic/digest/whatever will do.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You can do it via simple http auth

Example location section

        location /protected/ {
        proxy_pass http://192.168.1.1:1111;
        proxy_set_header Host $http_host;
        auth_basic            "Restricted-plz-auth-urself";
        auth_basic_user_file  /etc/nginx/passwds/htpasswd_protected;
    }

And add a password file to the path specified above, you may create it via htpasswd utility (I think apache2-utils package has this)

share|improve this answer

You can use auth basic, if you have this module compiled in.

like: auth_basic "closed site"; auth_basic_user_file htpasswd;

where htpasswd consist of user:password

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.