From How Fast Are Unix Domain Sockets? | Linux.com:
The Unix socket implementation can send and receive more than twice the number of messages, over the course of a second, when compared to the IP one.
Of course the increased speed and performance with Unix sockets instead of ports, etc. is only important for high traffic sites, because Ghost is already very fast. But in any case it’s nice to have it for possible traffic spikes.
Magentaize wrote (Ghost-CLI issue #417):
if I use NODE_ENV=production node current/index.js to start ghost, all things work properly, but if I use ghost start to start ghost, I cannot access my site and nginx says it cannot connect to socket (using the same config file).
Yes, Ghost works well with Unix sockets (see docs Unix Sockets - Config - Ghost Dodumentation, article Binding Ghost To A Unix Domain Socket - Igu.io, file core/server/ghost-server.js, etc.). The only problem is
ghost start
and
ghost restart
not yet supporting Unix sockets.
Apart from the one mentioned by Magentaize, another quick workaround (on Ubuntu 16.04) without restarting the server is to call the systemd service file created by Ghost-CLI, something like /etc/systemd/system/ghost_example-com.service, with:
sudo service ghost_example-com start
or
sudo service ghost_example-com restart
To test Unix sockets by modifying the default files created by Ghost-CLI, a very simple configuration that works well is the following.
In Ghost’s /var/www/ghost/config.production.json, replace
"server": {
"port": 2368,
"host": "127.0.0.1"
},
with
"server": {
"socket": {
"path": "/tmp/ghost.socket",
"permissions": "0660"
}
},
In Nginx’s /var/www/ghost/system/files/example.com.conf, replace
proxy_pass http://127.0.0.1:2368;
with
proxy_pass http://unix:/tmp/ghost.socket;
You can test the Nginx change:
sudo nginx -t
Also, if using socket permissions 0660
(which are Ghost’s default, so that the above permissions line is optional), then the Nginx user (usually www-data
) should be aded to the ghost
group, the socket owner:
sudo gpasswd -a www-data ghost
For this group assignment to take effect, there are various ways with no need to restart the server, that of course also would work.
Remember to reload the Nginx configuration and restart Ghost:
sudo nginx -s reload
sudo service ghost_example-com restart
Magentaize’s different configuration (#417) should equally work.
About a possible Ghost-CLI enhancement for Unix sockets, users can easily adapt the configuration files created by Ghost-CLI as explained above, but if ghost start
and ghost restart
, rather than giving error “Port is required” would directly use Ghost’s systemd service file when it exists, then I think just this would be enough to complete the already working Unix socket support for increased speed and performance.