I have another server for Ghost and proxy /blog into that server (nginx). as a result, when I load example.com/blog , Ghost tries to load assets from example.com/assets etc. this means I get a page without styling.
in config.js, I set url to ghost.example.com. I want to force Ghost to always use that as root domain
Hi @hadifarnoud, I'm afraid this doesn't make much sense!
The url you set in config.js is the URL that Ghost will use to generate any external URLs, if you want to run Ghost on a subdirectory, the subdirectory needs to be in the url in config.js, if you want to run Ghost on a subdomain, then you need to proxy the subdomain to Ghost.
Ghost is neither webserver nor DNS management tool, and nor should it be. Your nginx configuration needs to reflect the URL you want to use, and Ghost only needs to be told what that is.
when I add a directory to url, I get 'cannot GET /' error. it doesn' matter if Ghost is on the same server or not. so, I can't set url to example.com/blog
I did proxy Ghost in nginx. I used the server IP:GHOSTPORT. the homepage loads fine but every link is broken, as well as css/js/images
@hadifarnoud If you want to set the URL as ghost.example.com, you need to do the following:
ghost.example.com to your server IP addressserver_name directive and proxy the requests to the port where Ghost is running:server_name ghost.example.com www.ghost.example.com;
location / {
proxy_pass http://127.0.0.1:2368;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
config.js to http://ghost.example.com and you're done :)[!] Make sure you change the URL inside the right environment config block, development or production
I gave up to proxy example.com/blog to another server on a subdomain ghost.example.com. Ghost is now on the same server.
subdomain was working fine @ayrad but my issue is having it proxied on example.com/blog
it does load the page but no css or images are loading because it tries to load them from example.com/assets which will work if it was example.com/blog/assets (nginx will proxy it).
I cannot set url to example.com/blog in config.js
@hadifarnoud Well now I understand your issue. I see that the Ghost assets URL starts with / which takes the root folder as starting point instead of the subdirectory /blog/:
<link rel="stylesheet" type="text/css" href="/assets/css/screen.css?v=06bb7797a5" />
You can try this configuration.
@ErisDS may confirm us if that's right, otherwise tell us how to install Ghost on a subdirectory :)
@ayrad this is the exact tutorial I followed. Ghost is still loading everything from root directory. no css,js, or images work. I did manually add the /blog folder to assets but that does not solve the permalinks issue. not to mention all the other images I'll upload.
<link rel='stylesheet' href="/blog/{{asset "/css/style.css" type="text/css" media="all" }}"/>
I tried adding the directory to 'url', but as I said it breaks Ghost and gives me 'cannot GET /' error.
@hadifarnoud Well, It's not necessary to edit the asset url. I thought it wasn't possible to install Ghost on subdirectory, but actually you can... I just installed Ghost (v. 0.5.10) on a subdirectory which you can check here and it works just fine.
wget https://ghost.org/zip/ghost-0.5.10.zipunzip -uo ghost-0.5.10.zip -d /var/www/server.elladodelgeek.com/blog (on a subfolder of the main website root directory)config.js:npm install --productionNODE_ENV="production" pm2 start index.js --name ghost_subdir (I use pm2 here but you can run it directly for testing purposes by using npm start --production)server block:location ^~ /blog {
proxy_pass http://127.0.0.1:2368;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
BTW, the asset helper part inside the theme, I just left he Casper default one, which is {{asset "css/screen.css"}} and NOT {{asset "/css/screen.css"}} (no trailing slash ' /' at start)
It has been possible to install Ghost on a subdirectory for a very long time.
if you install it on a subdirectory like /blog/ and then set your config.url to yoururl.com/blog as well, then Ghost will serve the blog from yoururl.com/blog.
The 'cannot GET / error is then expected, because Ghost is not longer serving anything to /, it will only serve the blog if you request /blog. You would need to have some other service proxied to /.
@ErisDS @ayrad
I have done the exact same thing. even removed the node_modules before doing it.
here is my vhost config: https://gist.github.com/hadifarnoud/a76d93be62d76d62dc56
and my config.js (db info retracted): https://gist.github.com/hadifarnoud/845a60607763504c33e1
my ghost url: http://camva.ir/blog/
when I remove /blog from url both http://camva.ir/blog/ and http://camva.ir:2368/ work (just front page loads without css,js,imgs )
@hadifarnoud Seems like you already solved it. What was it? :)
update: I had a / at the end of proxy_pass URI. removed that and it works. Thanks for your support guys
@hadifarnoud Good news :)
Most helpful comment
update: I had a / at the end of proxy_pass URI. removed that and it works. Thanks for your support guys