How to Install Ghost with Nginx as a Reverse Proxy on Ubuntu 24.04
Install Ghost on Ubuntu 24.04 with the official Ghost-CLI, which sets up Nginx, MySQL, Let's Encrypt SSL and systemd, with an unattended option.
By the end of this guide you will have a Ghost site running on Ubuntu 24.04 LTS behind Nginx as a reverse proxy, with a Let's Encrypt certificate and a systemd service that keeps Ghost running. The whole setup is done by Ghost-CLI, the official installer, and it can run without prompts if you want to script it. The same steps apply to Ubuntu 22.04.
Ubuntu 14.04 is long out of support, and the third-party boot scripts that used to install Ghost with a self-signed certificate are no longer needed or safe to pipe into a shell: Ghost-CLI now configures Nginx, TLS and the service for you.
Requirements
- A server with Ubuntu 24.04 or 22.04 and at least 1 GB of memory.
- A registered domain with an A record pointing to the server's IP address. Set this up first: the certificate cannot be issued until the name resolves. This guide uses
example.com. - Root access over SSH to create the first user.
Ghost's production stack is Nginx, MySQL 8 and a supported Node.js LTS release. At the time of writing the Ghost documentation lists Node.js 22 and 24 as supported and uses 22 in its install guide.
Step 1: Create a user
Log in as root and create an unprivileged user with sudo rights. Do not name the user ghost; that name conflicts with Ghost-CLI.
adduser deploy
usermod -aG sudo deploy
su - deploy
Run all following commands as this user.
Step 2: Update the system and install Nginx
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx
If the ufw firewall is active, allow HTTP and HTTPS:
sudo ufw allow 'Nginx Full'
Step 3: Install MySQL and set a root password
sudo apt-get install mysql-server
On Ubuntu the MySQL root account logs in through the local socket by default, which Ghost-CLI cannot use. Give it a password:
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH 'caching_sha2_password' BY 'your-new-root-password';
FLUSH PRIVILEGES;
exit
Ghost-CLI only uses this account during installation to create a database and a separate, restricted MySQL user for the site.
Step 4: Install Node.js
Add the NodeSource repository for the Node.js release that Ghost supports and install it:
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=22
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y
Check the version:
node --version
Step 5: Install Ghost-CLI
sudo npm install ghost-cli@latest -g
Step 6: Create the site directory
Ghost must be installed in its own directory, owned by your user. Do not install it in /root or in your home directory.
sudo mkdir -p /var/www/example
sudo chown deploy:deploy /var/www/example
sudo chmod 775 /var/www/example
cd /var/www/example
Step 7: Install Ghost
Interactive install
ghost install
Ghost-CLI checks the system, downloads Ghost and asks a few questions:
- Blog URL — the full address including the protocol,
https://example.com. An IP address does not work. - MySQL hostname — press Enter for
localhost. - MySQL username and password —
rootand the password from step 3. - Ghost database name — accept the suggestion; the database is created for you.
- Set up a ghost MySQL user? — yes. Ghost then runs with an account limited to its own database.
- Set up Nginx? — yes. This writes the reverse proxy configuration for your domain.
- Set up SSL? — yes, and enter an email address. A Let's Encrypt certificate is requested and Nginx is configured for HTTPS.
- Set up systemd? — yes. Ghost runs as a service and starts at boot.
- Start Ghost? — yes.
Automated install without prompts
For a scripted setup, pass the answers as options and add --no-prompt. Every required value must then be on the command line:
ghost install \
--url https://example.com \
--db mysql --dbhost localhost \
--dbuser root --dbpass 'your-new-root-password' --dbname ghost_prod \
--sslemail admin@example.com \
--process systemd \
--no-prompt
The password ends up in your shell history when you type it this way, so in a provisioning script read it from a variable or a protected file instead. Run ghost install --help to see the full list of options for your Ghost-CLI version.
Step 8: Verify and finish the setup
List the Ghost instances on the server and check that yours is running:
ghost ls
Test the proxy and the certificate from the command line. You should get an HTTP response from Nginx over HTTPS without a certificate warning:
curl -I https://example.com
Then open https://example.com/ghost in a browser and create the admin account. Do this straight away: until you do, the setup page is open to anyone who finds it.
Maintenance
Run Ghost-CLI commands from the site directory as your user, not as root:
cd /var/www/example
| Command | What it does |
|---|---|
ghost update | Upgrades Ghost to the latest version; ghost update --rollback reverts a failed upgrade. |
ghost backup | Creates a zip archive of content, members, themes and media. |
ghost restart | Stops and starts the instance. |
ghost log | Shows the last lines of the log; add -e for errors only and -f to follow. |
ghost doctor | Checks the system for problems that affect installing or updating Ghost. |
ghost setup ssl | Requests the Let's Encrypt certificate later if you skipped it during installation. |
Keep Ghost-CLI itself current with sudo npm install -g ghost-cli@latest, and check the supported Node.js versions in the Ghost documentation before a major Ghost upgrade. The official references are the Ubuntu install guide and the Ghost-CLI documentation.
Frequently asked questions
The SSL step failed. What now?
Almost always the domain did not yet point to the server, or ports 80 and 443 were closed. Fix the DNS record or the firewall, wait for the record to resolve, then run ghost setup ssl in the site directory.
Can I run Ghost on a server with less than 1 GB of memory?
Ghost's documentation asks for at least 1 GB. On smaller servers the installation step is usually what runs out of memory. Adding swap space can get you through the install, but a 1 GB server is the realistic minimum for Ghost together with MySQL and Nginx.
Can I use Ubuntu's own Node.js package instead of NodeSource?
Only if its version is one that Ghost supports. Ghost checks the Node.js version at install and update time and refuses unsupported ones, which is why the official guide installs a specific major release from NodeSource.
Can I host a second Ghost site on the same server?
Yes. Create another directory under /var/www, change into it and run ghost install again with the other domain. Each site gets its own database, Nginx configuration and systemd service, and each needs its share of memory.