Links not using the port specified in the URL

Hi all,

I set up ghost this weekend. After jumping through some hoops I have a working local installation using a dedicated ghost user (called ghostuser rather than ghost as the ghost user is ‘special’), nginx and mysql but I have one problem remaining.

In my ghost config I have:

{
  "url": "http://192.168.0.17:84",
  "server": {
    "port": 2370,
    "host": "127.0.0.1"
  },

I have nginx operating as a proxy but the links generated are always to port 2370 not to port 84. I also have in my nginx config:

upstream ghost_backend {
   server 127.0.0.1:2370;
}

server {
   listen 84;
   server_name _;

   location / {
            proxy_pass http://ghost_backend;
            proxy_set_header Host $host:84;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
   }
}

I’ve tried various things but I’m still not sure if the problem is on the nginx or ghost side.

As I understand it including the port in the URL should tell ghost to use that port in all generated links but it does not seem to be working.
Any advice on how I can diagnose this?

I should mention I am currently using this within my intranet only and don’t have a domain name or SSL at present.

1 Like

Can you confirm that the URL is correctly reflected in Ghost? On the server, run

curl http://127.0.0.1:2370/ghost/api/site/ | sed 's/,/\n/g' | grep url
1 Like

Never mind the sed that returns an error pretty printed below:

>curl http://127.0.0.1:2370/ghost/api/site/ | jq .
{
  "errors": [
    {
      "message": "Resource not found",
      "context": null,
      "type": "NotFoundError",
      "details": null,
      "property": null,
      "help": null,
      "code": null,
      "id": "d47a4a50-e04a-11ee-854b-dda1175f6a24",
      "ghostErrorCode": null
    }
  ]
}
1 Like

Gaah, typos! It’s good to know you have jq installed :stuck_out_tongue:

Can you try with http://127.0.0.1:2370/ghost/api/admin/site/

and with jq you can do .site.url

1 Like
>curl http://127.0.0.1:84/ghost/api/admin/site/
“http://192.168.0.17:2370/”

You’ll want to try on port 2370 ( the Ghost port) and use the fixed path

curl http://127.0.0.1:84/ghost/api/admin/site/ | jq .site.url
curl http://127.0.0.1:2370/ghost/api/admin/site/ | jq .site.url

Both give:

http://192.168.0.17:2370/”

I have a regular apache on port 80 so I’m proxying to port 84. I don’t think its the problem but I can try temporarily switching over.

That’s the reason Ghost is giving the “wrong” URL - it’s configured to! :smiley:

Can you confirm that the Ghost URL is correct - ghost config get url? If it is, can you restart Ghost to make sure the changes were picked up?

But:

> ghost config get url

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org

http://192.168.0.17:84

and I have restarted ghost several times.

I gave up and reinstalled ghost to another directory and now it is behaving correctly.

My few test images got lost but that’s okay.

I had to move my installation from /home/ghostuser to /home/ghostuser/ghost. ghost thinks it owns everything in the directory its installed to which is definitely not the case if you install it in the home folder of a user.