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

ghost nodejs deployment

WBOY
Release: 2023-05-18 10:29:38
Original
719 people have browsed it

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
    Copy after login
  3. Install Node.js:

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

    cd ghost
    npm install --production
    Copy after login
  6. Run Ghost:

    npm start --production
    Copy after login
    Copy after login

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
    Copy after login
  2. Create the Nginx configuration file:

    sudo nano /etc/nginx/sites-available/ghost
    Copy after login

    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;
        }
    }
    Copy after login

    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/
    Copy after login
  4. Restart the Nginx service:

    sudo service nginx restart
    Copy after login
  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
      Copy after login
    2. Then, enable the certificate:

      sudo certbot --nginx
      Copy after login

      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
      Copy after login
    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
      }
      Copy after login
    4. Restart Ghost:

      npm start --production
      Copy after login
      Copy after login

    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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template