Home >Web Front-end >Front-end Q&A >ghost nodejs deployment

ghost nodejs deployment

WBOY
WBOYOriginal
2023-05-18 10:29:38740browse

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:

  1. Log in to your DigitalOcean account.
  2. On the console page, click "Create Droplet".
  3. Select your operating system, billing plan, and data center location. In this example we will select Ubuntu 18.04, Standard, SFO2.
  4. Select your SSH key or create a new SSH key.
  5. Click the "Create Droplet" button.

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.

  1. Use SSH to log into your virtual machine.
  2. Update the package list and upgrade all installed packages:

    sudo apt update
    sudo apt upgrade
  3. Install Node.js:

    curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
    sudo apt-get install -y nodejs
  4. 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
  5. Install dependencies in the Ghost directory:

    cd ghost
    npm install --production
  6. 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.

  1. Install Nginx as Ghost’s reverse proxy server.

    sudo apt-get install nginx
  2. 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.

  3. Make Nginx aware of the existence of this configuration file:

    sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/
  4. Restart the Nginx service:

    sudo service nginx restart
  5. Download SSL Certificate

    1. Use Letsencrypt Certbot to apply for a certificate. In your SSH terminal, run the following command:

      sudo apt install certbot python3-certbot-nginx
    2. 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.

  6. Enable HTTPS

    Once your SSL certificate is enabled and verified successfully, you can configure the Ghost application to only run over HTTPS.

    1. Close Ghost first:

      npm stop --production
    2. Open the Ghost configuration file config.production.json.
    3. Add the following in the "server" section:

      "url": "https://your_domain.com",
      "server": {
          "port": 2368,
          "host": "127.0.0.1"
      },
      "ssl": {
          "force": true
      }
    4. 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn