Home > Article > Web Front-end > ghost nodejs deployment
As Node.js becomes more popular, more and more developers are using it to create backend applications. Ghost is an open source blogging platform based on Node.js, which uses many popular Node.js technologies and libraries to help users create beautiful and feature-rich blogs.
This article will show you how to host a Node.js application on Ghost and how to configure a custom domain name and SSL certificate for it.
Step 1: Choose a cloud server
First, you need to choose a cloud server to host the Ghost application. There are many cloud server providers in the market such as AWS, DigitalOcean, Linode, etc. This article will use DigitalOcean as an example to illustrate.
Step 2: Create a Virtual Machine
Creating a virtual machine on DigitalOcean is easy. Follow these steps:
DigitalOcean will create and start a new virtual machine for you.
Step 3: Install Node.js and Ghost
Once your virtual machine is active, you can use SSH to connect to the virtual machine and install Node.js and Ghost.
Update the package list and upgrade all installed packages:
sudo apt update sudo apt upgrade
Install Node.js:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt-get install -y nodejs
Download Ghost and unzip it:
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost-latest.zip unzip -uo ghost-latest.zip -d ghost
Install dependencies in the Ghost directory:
cd ghost npm install --production
Run Ghost:
npm start --production
If everything is normal, you can enter the server's IP address and Ghost's default port 2368 in the browser to see the Ghost installation page.
Step 4: Configure a custom domain name and SSL certificate
By default, the Ghost server can only be accessed by IP address. If you want to configure a custom domain name and SSL certificate for your Ghost application, you must perform the following steps.
Install Nginx as Ghost’s reverse proxy server.
sudo apt-get install nginx
Create the Nginx configuration file:
sudo nano /etc/nginx/sites-available/ghost
Then, enter the following:
server { listen 80; listen [::]:80; server_name your_domain.com; location / { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://127.0.0.1:2368; } }
This configuration file will allow Nginx to act as a gateway for Ghost. Please remember to replace your_domain.com
with your own domain name.
Make Nginx aware of the existence of this configuration file:
sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/
Restart the Nginx service:
sudo service nginx restart
Download SSL Certificate
Use Letsencrypt Certbot to apply for a certificate. In your SSH terminal, run the following command:
sudo apt install certbot python3-certbot-nginx
Then, enable the certificate:
sudo certbot --nginx
This command will use the domain name specified in the Nginx configuration file to Your Ghost application generates an SSL certificate.
Enable HTTPS
Once your SSL certificate is enabled and verified successfully, you can configure the Ghost application to only run over HTTPS.
Close Ghost first:
npm stop --production
Add the following in the "server" section:
"url": "https://your_domain.com", "server": { "port": 2368, "host": "127.0.0.1" }, "ssl": { "force": true }
Restart Ghost:
npm start --production
Now, your Ghost application is running on your custom domain name and HTTPS.
Conclusion
Congratulations! With this article, you already know how to host a Node.js application on Ghost and configure a custom domain name and SSL certificate. These steps can also be used to host any other Node.js application.
The above is the detailed content of ghost nodejs deployment. For more information, please follow other related articles on the PHP Chinese website!