"Bad request" when trying to access ghost admin

I’ve been running for a little while 3 blog/sites with ghost using yunohost. When I started ghost was around version 3.40 and now all sites are updated to version 5.8.3 (the latest available at the moment in yunohost).
For two sites, I created my own theme, and recently I noticed there was some strange behavior in them so I wanted to investigate the theme, but doing this I noticed I’m not able to access to the ghost admin panel on both sites that run the custom theme (I get a blank page with written “Bad request”), the other one seem to be working fine, so I don’t really get what the issue is really.
Anyone would have some idea on where the issue may come from or how to investigate it?

Thanks a lot in advance for the help :)

1 Like

I had to switch to the Ghost user (sudo -u ghost bash, or ghost__2 in my case), and run a few commands. But first, remember to make sure your Ghost service is stopped!

systemctl stop ghost.service # or ghost__2.service, etc.
sudo -u ghost bash # or ghost__2, etc.

At this point, you will be logged in as your system’s dedicated Ghost user. From here, you can run:

cd # Goes to the root directory of your Ghost installation
cd ghost/admin # Where the admin source files are
yarn build --environment/production

# Depending on your server speed, this would be a good time to
# go grab a coffee ;)

ls ~/ghost/core/core # should have a 'built' directory inside

After that, exit and systemctl start ghost and you should be ready to go!

If you want to debug the output more for some reason, instead of starting Ghost through systemctl, you can just cd into the ghost user’s home directory and run,

  • yarn dev for a dev server,
  • NODE_ENV=production yarn dev for a dev server that runs by your production settings (i.e. available on the configured YunoHost URL), or
  • NODE_ENV=production yarn start for the actual final server.

Of course, switch back to systemctl once done to avoid having your blog ghost you when you close the terminal :wink:

Hope that helps! It did for me. Also let me know if it works, because in that case the extra build command should probably be added to the install script; maybe I can create a pull request.

Thanks a lot for your answer @badrihippo :slight_smile:
I was just trying to apply your suggestion and this is the situation I’m having:
The ghost user doesn’t have a home directory, so I cd into /var/www/ghost__3, then ghost/admin.
After that running yarn build --environment/production gives me the following error:

yarn run v1.22.19
warning Skipping preferred cache folder "/home/ghost__3/.cache/yarn" because it is not writable.
warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-995".
$ ember build --environment/production
warning Cannot find a suitable global folder. Tried these: "/usr/local, /home/ghost__3/.yarn"

Error: EACCES: permission denied, mkdir '/home/ghost__3/.config/configstore'
You don't have access to this file.

So I guess there is a problem of configuration of the home directory of the ghost user or app somehow.

That’s odd. If your app is ghost__3 then usually the would also be ghost__3 with the home directory as /var/www/ghost__3. For some reason, your user is still trying to do things in the (non-existent) /home/ghost__3 instead. (Did you manually create a user at some point or was it automatically created?)

Not sure where to go from here, but can you tell me:

  • The name of your Ghost app (ghost__3?)
  • The name of the user you are logging in as (also ghost__3?)
  • The directory you end up in when you switch to the Ghost user and run cd without any arguments (this should normally take you to the home directory, but I’m not sure what happens if the home directory doesn’t exist)

Also what are the permissons (ls -la) of the files in /var/www/ghost__3?

Finally, perhaps you could check if there’s some way (eg. environment variables) to override the default places yarn and ember try to find things, and force it to be in your Ghost installation directory.

I also realised this post should probably belong in the YunoHost forum and not here? We’re getting into very YunoHost territory right now, which means there’s a lot more chance somebody will be able to help you out there!

I created a post in the yunohost forum ;)

To answer briefly to your question:

  • the app is named ghost__3
  • I didn’t tweak in any way the app or it’s user (didn’t manually create a user named ghost__3)
  • following your suggestions, I was logging in as ghost__3
  • if I do cd as ghost__3, I get an error that /home/ghost__3 doesn’t exist
  • the permissions in /var/www/ghost__3:
drwxr-x---    10 ghost__3 www-data    4096 Sep 29 23:40 .
drwxr-xr-x+   12 root     root        4096 Oct  5 03:36 ..
drwxr-x---     5 ghost__3 www-data    4096 Sep 29 23:44 .cache
drwx------     3 ghost__3 www-data    4096 Sep 29 23:40 .config
drwxr-x---     3 ghost__3 www-data    4096 Sep 29 23:32 content
-rw-r-----     1 ghost__3 www-data     312 Aug  9 17:02 .editorconfig
drwxr-x---    42 ghost__3 www-data    4096 Aug  9 17:02 ghost
-rw-r-----     1 ghost__3 www-data     122 Aug  9 17:02 .gitattributes
drwxr-x---     5 ghost__3 www-data    4096 Aug  9 17:02 .github
-rw-r-----     1 ghost__3 www-data    1025 Aug  9 17:02 .gitignore
-rw-r-----     1 ghost__3 www-data     121 Aug  9 17:02 .gitmodules
-rw-r-----     1 ghost__3 www-data    1065 Aug  9 17:02 LICENSE
drwxr-x---  1891 ghost__3 www-data   69632 Sep 29 23:42 node_modules
drwxr-x---     4 ghost__3 www-data    4096 Sep 29 23:40 .npm
-rw-r-----     1 ghost__3 www-data    3190 Sep 29 23:41 package.json
-rw-r-----     1 ghost__3 www-data    2860 Aug  9 17:02 PRIVACY.md
-rw-r-----     1 ghost__3 www-data    5773 Aug  9 17:02 README.md
-rw-r-----     1 ghost__3 www-data     518 Aug  9 17:02 SECURITY.md
drwxr-x---     3 ghost__3 www-data    4096 Sep 29 23:40 .yarn
-rw-r-----     1 ghost__3 www-data 1080248 Sep 29 23:41 yarn.lock
-rw-r-----     1 ghost__3 www-data     111 Sep 29 23:32 .yarnrc
-r--------     1 ghost__3 www-data       0 Sep 29 23:32 .yarnrc.yml

I’ll investigate as soon as I can about yarn and ember variables, to see if I can find solutions.

Continuing the discussion on the YunoHost forum :slightly_smiling_face: