Installing ghost on a different Server & configuring subdirectory on domain

Trying to setup ghost at url Image optimization & performance - deliver faster websites & apps.

https://imagecompressor.io - server 1
https://imagecompressor.io/blog - Digital Ocean droplet (ex ip 159.65.193.48)

I have been successfully able to run ghost using 1-click on Digital Ocean. But not able to link it with the domain. I have gone through various articles, tried quite a few nginx configurations, can’t get it to work.

nginx config at imagecompressor.io

# Default server configuration
#
server {

	root /var/www/imagecompressio-js/serve;

	server_name imagecompressor.io;

	location /images {
		alias /var/www/images;
		expires 1d;
		add_header Cache-Control public;
		add_header Content-disposition "attachment; filename=$1";
	}

    # ghost blog
	location ^~ /blog {
		proxy_pass http://159.65.193.48;
		proxy_redirect off;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri /index.html =404;
		expires -1;
	}

 	 location ~* \.(?:css|js)$ {
		access_log        off;
    		log_not_found     off;
		add_header        Cache-Control "no-cache, public, must-revalidate, proxy-revalidate";
  	}

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/imagecompressor.io/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/imagecompressor.io/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
	server_name api.imagecompressor.io;
	location / {
             	proxy_pass http://localhost:5000;
             	proxy_http_version 1.1;
             	proxy_set_header Upgrade $http_upgrade;
             	proxy_set_header Connection keep-alive;
             	proxy_set_header Host $host;
             	proxy_cache_bypass $http_upgrade;
		proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        	proxy_set_header   X-Forwarded-Proto $scheme;
         }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/imagecompressor.io/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/imagecompressor.io/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = imagecompressor.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

	listen 80 default_server;
	listen [::]:80 default_server;

	server_name imagecompressor.io;
    return 404; # managed by Certbot
}

server {
    if ($host = api.imagecompressor.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


	listen 80;
	server_name api.imagecompressor.io;
    return 404; # managed by Certbot
}

My first question is - what should the url be provided to ghost CLI while installing? http://159.65.193.48 or https://imagecompressor.io/blog?

2nd - Are there any additional nginx configurations (or any other settings) that need to be tweaked on the Digital Ocean droplet?

You will find on the forum. Just search a bit :)

I have searched the entire digital ocean, server fault & this forum.
This seems to be the closest solution, but its not working for in my case.
All of the examples work well when the domain & the ghost blog are on the same server/ip address.

Firstly, when you’re installing Ghost, it needs to known what its own URL is going be. So in your case Image optimization & performance - deliver faster websites & apps.

Secondly, this setup is similar to proxying to Ghost(Pro) except you have an IP instead of a ghost.io domain.

https://docs.ghost.org/faq/can-i-run-ghost-from-a-subdirectory/#reverse-proxy-rules

If you provide the details of what it is exactly that is happening that’s undesirable, I can probably help more. My first guess would be that you need to get Ghost setup with the HTTPS URL, and then make sure your reverse proxy is passing HTTPS as the x-forwarded-proto.

Thanks @Hannah

Booted a new droplet with 1 click ghost install on digital ocean. ghost ls -

Name               │ Location       │ Version │ Status               │ URL                             │ Port │ Process Manager │
│ imagecompressor-io │ /var/www/ghost │ 2.14.0  │ running (production) │ https://imagecompressor.io/blog │ 2368 │ systemd         │

@Hannah - I followed the article you posted & updated nginx configuration on root/domain server.

location /blog/ {
		resolver 1.1.1.1 8.8.8.8;
		client_max_body_size 10G; # Required for uploading large files
		proxy_pass http://142.93.237.106;
		proxy_redirect off;
        proxy_set_header Host https://imagecompressor.io/;
        #  proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-Host https://imagecompressor.io/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}

Going to Image optimization & performance - deliver faster websites & apps results in a timeout. https://imagecompressor.io/blog/ghost results in a 400 bad request. This error seems to be coming from the ghost droplet.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.