1

I have a ghost blog running through a Nginx proxy and I would like to enable http authentication for the blog. I have the following server{} block in my nginx .conf file:

listen 80;
listen [::]:80;

server_name docs.example.com; 

root /usr/share/nginx/html;
index index.html index.htm;

client_max_body_size 10G;

auth_basic  "closed website";
auth_basic_user_file /etc/nginx/htpasswd;

location / {
    proxy_pass http://localhost:2777;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
}

This configuration created an infinite redirect loop at the sign-in page for the ghost admin interface when logging in. Here is the firefox console log:

GET  http://docs.my-site.com/ghost/api/v0.1/users/me/?status=all&include=roles 

401 Unauthorized
{"type":"error","message":"Please Sign In","status":"passive"}

Anyhow, It seems like all I have to do is disable auth_basic for location /ghost/ and I would be good to go:

location /ghost/ {
    auth_basic  off;
    proxy_pass http://localhost:2777;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
}

I added this block to the .conf file and, unfortunately, the redirect loop still occurs if I try to log in after I am authenticated on the main page. I can sign in if I go to Firefox's history menu, clear my login credentials, and navigate directly the the admin sign-in pane. Not great be we are getting somewhere. Here is the strange part. After following this process and signing in, Firefox prompts me with an authentication prompt "Restricted". I can click cancel and interact with the settings and menus on the admin interface just fine. But what the heck is going on?

Still tinkering, and I will post updates if I make any progress. Any thoughts on how to get this working would be much appreciated. Thanks in advance.

UPDATE

The process is less buggy in Chrome – there is no infinite redirect loop. Still get a prompt for credentials after logging into the admin interface.

0

Your Answer

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