?

Nginx Subdirectory Setup

Β»

It's possible to setup a reverse proxy using an nginx configuration to establish a subdirectory on Ghost(Pro).

For this configuration to work successfully, you must be on a Business plan with a subdirectory enabled via [email protected]. You must also paste the exact configuration below into your nginx configuration file, updating each line as specified so that it meets our reverse proxy rules.

The below configuration has been tested and works with these exact settings if there are no conflicting top-level config issues.
server {
    listen 80;

    server_name <yourdomain.com>; # Replace with your domain

    # include any global or shared config
    # include /etc/nginx/conf/your-config-here.conf;
 
    # redirect to SSL
    return 301 https://$host$request_uri; 
}

server {
    listen 443 ssl default_server;

    server_name <yourdomain.com>; # Replace with your domain

    # Your SSL Certificate details. Replace with your own SSL setup
    # ssl_certificate /path/to/cert;
    # ssl_certificate_key /path/to/key;

    location /blog/ {
        client_max_body_size 10G; # Required for uploading large files
    
        # Proxy Settings, all required
        resolver 1.1.1.1 8.8.8.8; # Prevent caching the upstream IP - use preferred DNS resolvers or leave as default
        set $ghost_url https://<yoursubdomain>.ghost.io; # Replace with your subdomain
        proxy_pass $ghost_url; # Variable name must match line above, use of variable required for resolver
        proxy_redirect off;
        proxy_set_header Host <yoursubdomain>.ghost.io; # Replace with your subdomain
        proxy_set_header X-Forwarded-Host <yourdomain.com>; # Replace with your domain
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}