Moved Permanently. Redirecting to https://XXXXX

Hi, I am currently running ghost on docker, with a load balancer in front of it, and I get this issue which I don’t understand:

ubuntu@qcloud:~/data/compose/ghost$ curl https://blog.xoxox.io
Moved Permanently. Redirecting to https://ghost/
the following is the my settings of everything

Ghost Version: docker image: ghost:1-alpine

Ghost compose file:

blog:
image: ghost:1-alpine
restart: always
ports:
- 2368:2368
volumes:
- ~/data/docker_volumes/ghost/content:/var/lib/ghost/content
environment:
- MAIL_FROM=will@xoxox.io
- url=https://blog.xoxox.io

Nginx compose file:

proxy:
image: nginx
ports:
- “80:80”
- “443:443”
volumes:
- ./certs:/etc/nginx/certs
- ./conf.d/blog.xoxox.io.conf:/etc/nginx/conf.d/blog.xoxox.io.conf

Nginx conf:

upstream ghost {
server qcloud.xoxox.io:2368;
}
server {
server_name blog.xoxox.io;
listen 80;
return 301 https://$host$request_uri;
}
server {
server_name blog.xoxox.io;

listen 443 ssl http2;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /etc/nginx/certs/blog.xoxox.io.crt;
ssl_certificate_key /etc/nginx/certs/blog.xoxox.io.key;

client_max_body_size 0;

location / {
	proxy_pass http://ghost;
}

}

PS: if I remove url environment variable, it goes right,
- url=https://blog.xoxox.io
but the blog site does not handle links right.

If you are running multiple instances of Ghost for the same blog that won’t work. From the install docs:

You’re nginx config is not passing the necessary headers through to Ghost so it won’t know what URL it’s serving. Ghost-CLI is the recommended/supported way to install Ghost, it has nginx templates that you should follow if installing your own way.

according to docker-compose.yml of ghost, it runs just 1 instance. and the url nerver changed.

You’re good on the multi-instance side of things then but you’ll still need to fix your nginx config for Ghost to work correctly.

after I added the following headers from templete nginx file to conf
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
nothing changes

thanks anyway

Just to be sure, check where the node.js port is listening to, as well as your blog sudo netstat -peanut

Also why are you proxying to ghost.org?
Try changing that to:

proxy_pass http://127.0.0.1:2368;  

where 2368 is the port where node is running or put whichever server you’re using

nginx is not on the same node which blog is deployed. nginx is deployed in USA, but blog is deployed in China, I am sure the blog is accessable, because if url is not set in the environment, redirect is successful.
proxy_pass http://ghost;
above line is just pointing to the upstream:
upstream ghost {
server qcloud.xoxox.io:2368;
}

Looks like I’m having related issue: https://forum.ghost.org/t/http-x-forwarded-proto-not-used-by-all-requests

i.e. when i change the http to https in the json config (url variable) i see the same Moved Permanently status and infinite redirect loop in Chrome.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.