Install Ghost alongside other nodejs web app

Hi,
I am trying to install Ghost on my server, which is already running an express app with nginx. I have been trying to find some ways through but there have not been any effective solutions yet.
I’d really appreciate any help or just hint is also nice.

Addition: I’m working on an Oracle VM, ubuntu 20.04 LTS. And yes, the express app use port 80.

Clarification: the express app is serving as www.nhonho.tech , I want to have Ghost up at blog.nhonho.tech or www.nhonho.tech/blog . I also use Cloudflare as dns for my domain.

Update: I have installed Ghost on blog.nhonho.tech, but now Ghost also goes to nhonho.tech. How can I advoid that?
Update 2: If I access the web page by IP, it shows the express app, which is supposed to be at nhonho.tech

My nginx configuration:

server
{
 listen 443 ssl http2;
 listen [::]:443 ssl http2;

 server_name nhonho.tech www.nhonho.tech;
 root /usr/share/das-express/bin;
 ssl_certificate /etc/ssl/certs/cloudflare_nhonho.tech.pem;
 ssl_certificate_key /usr/share/das-express/bin/key.key;
 ssl_client_certificate /usr/share/das-express/bin/li.pem;
 ssl_verify_client on;

 location / {
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Forwarded-Proto $scheme;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header Host $http_host;
     proxy_pass http://127.0.0.1:8080;

 }

 location ~ /.well-known {
     allow all;
 }

 client_max_body_size 50m;
}

server
{
  listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name blog.nhonho.tech;
    root /var/www/sitename/system/nginx-root;

    ssl_certificate /etc/letsencrypt/blog.nhonho.tech/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/blog.nhonho.tech/blog.nhonho.tech.key;
    include /etc/nginx/snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;

    }
}

You can install ghost normally & it wont affect your current node web-apps. Ghost uses port 2368 Just make sure the port is not being used with another process.

I installed Ghost at blog.nhonho.tech, it runs fine, the problem now is Ghost also shows at nhonho.tech.

This might be a webserver config issue. Can you please share your webserver config here or in DM?

I’ve updated my nginx configuration on post. Can you spot any problems?

make sure on ghost config.production.json file the URL is defined as https://blog.nhonho.tech

Nginx server block seems fine but what I am suspecting both are in the same config file. Did you create a separate config file for your ghost instance ? If not then follow below:

create a nginx server block for blog

sudo nano /etc/nginx/sites-available/blog.nhonho.tech

cut the blog config to the new file /etc/nginx/sites-available/blog.nhonho.tech

server {

    listen 80;
    server_name blog.nhonho.tech;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name blog.nhonho.tech;
    root /var/www/sitename/system/nginx-root;

    ssl_certificate /etc/letsencrypt/blog.nhonho.tech/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/blog.nhonho.tech/blog.nhonho.tech.key;
    include /etc/nginx/snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;

    }
}

Now enable the newly created nginx server block

sudo ln -s /etc/nginx/sites-available/blog.nhonho.tech /etc/nignx/sites-enabled/

Restart Nginx

sudo systemctl restart nginx

After restart it should work

I created blog.nhonho.tech.conf and nhonho.tech.conf (the ghost setup create file with .conf)

the nhonho.tech.conf:

    listen 80;
    listen [::]:80;

    server_name nhonho.tech www.nhonho.tech;
    root /usr/share/das-express;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:8080;
    }

}

The blog.nhonho.tech.conf :

    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name blog.nhonho.tech;
    root /var/www/sitename/system/nginx-root;

    ssl_certificate /etc/letsencrypt/blog.nhonho.tech/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/blog.nhonho.tech/blog.nhonho.tech.key;
    include /etc/nginx/snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;

    }
}

Main site nhonho.tech is now good, except that Ghost site blog.nhonho.tech is now nowhere.
Also, when I run nginx -t, it returned:

root@localhost:/etc/nginx/sites-enabled# nginx -t
nginx: [warn] conflicting server name "blog.nhonho.tech" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "blog.nhonho.tech" on [::]:443, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

I reinstalled nginx and changed Ghost from https to http, I’ll let the encrypt to Cloudflare.
The web seems to run fine now.
I think the problem is the different protocols used by two app, express use http while Ghost use https. Now they both use http and Cloudflare will take care of the rest.

It is possible to have multiple HTTPS sites on your web-server - it’s almost all down to your NGINX config. It’s also easy to mix and match HTTP and HTTPS. There is lots of NGINX help available via Google.

From the comments above it looks like you had both old and new config setup at the same time in the /etc/nginx/sites-enabled folder - this is why NGINX complained about duplicate servers.

HTTPS is important as it lets your readers verify that they have connected to your actual site, and not to another server pretending to be you. It also protects your Ghost username/password when you login to your Admin pages.

You should be aware that if you connect via an IP to your HTTPS server, NGINX will choose the FIRST server in /etc/nginx/sites-enabled/’ that is listening on 443 - so you can manage this using careful naming of the links in this folder - that’s why lots of folks use link-names like 00_default, 10_nhonho.tech, 20_blog-nhonho.tech etc.