2

After generating the htpasswd file online, nginx gives me the error "nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/sites-enabled/htpasswd:2". The weird thing is, there's only one line. My config file is as follows:

server {
    listen 80;

    index index.html
    auth_basic "User: (username) Password: (password)";
    auth_basic_user_file htpasswd;
    location / {
         proxy_pass http://localhost:8080;
    }
}

I'm curious as to why this is. Thanks.

Edit: the contents of my htpasswd are as follows: xxx:$apr1$xxx

  • You’re missing a semicolon at the end of the index line. That’s probably it. – Daniel B May 7 '16 at 17:46
  • @DanielB First, the error was referencing the htpasswd file, and second, adding that didn't do anything. – Dash May 7 '16 at 18:44
  • Does the file exist at /etc/nginx/sites-enabled/htpasswd? Please include it in your question. You can replace passwords and usernames with xxx. – Daniel B May 7 '16 at 19:06
  • @DanielB edited. – Dash May 8 '16 at 22:18
4

You placed the htpasswd in the sites-enabled directory of nginx.
In the nginx.conf, there is probably a line like this:

include /etc/nginx/sites-enabled/*;

So all files in that directory are treated as nginx config file. The content has nothing to do with nginx configuration and therefore you'll get that error.
You need to place that file somewhere else and use the correct path in your auth_basic_user_file option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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