I'm a beginner using a reverse proxy or managing technical infrastructure. I have my main app (react + nginx) on a server and I'm trying to install Ghost on a subfolder https://tinymentions.io/blog on the same server as my main app.
Unfortunately, I'm not able to successfully configure Nginx to properly serve my Ghost blog. When I visit the URL ttps://tinymentions.io/blog I get an error: "HTTP/1.1 404 NOT FOUND"
I have searched the Ghost forum, Stack Overflow and all over Google, tried different approaches and unfortunately, I'm still not able to come up with a solution for this problem. Every time I tried a new approach, I restarted nginx with sudo service nginx restart
but with no luck.
I would appreciate any help with this. If I'm not explaining myself correctly and/or need more information, please let me know.
- What's your URL?
My main app is on https://tinymentions.io/
- Ghost URL
- What version of Ghost are you using?
Ghost-CLI version: 1.15.0 Ghost version: 3.35.5
- What configuration?
This is my NGINX config file:
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name tinymentions.io www.tinymentions.io;
client_max_body_size 4G;
root /var/www/tiny-mentions/build;
index index.html;
location / {
try_files $uri $uri/ @proxy_to_app;
}
location /blog {
proxy_http_version 1.1;
proxy_set_header Update &http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://localhost:2368;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_connect_timeout 25000s;
proxy_read_timeout 25000;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
proxy_redirect off;
proxy_pass http://localhost:5000;
}
ssl_certificate /etc/letsencrypt/live/tinymentions.io/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/tinymentions.io/privkey.pem; # managed by Certbot
}
server {
if ($host = www.tinymentions.io) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = tinymentions.io) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name tinymentions.io www.tinymentions.io;
return 301 https://$server_name$request_uri;
}
The following is my config.production.json file:
{
"url": "http://tinymentions.io/blog",
"server": {
"port": 2368,
"host": "127.0.0.1"
},
"database": {
"client": "mysql",
"connection": {
"host": "localhost",
"user": "hidden",
"password": "hidden",
"database": "hidden"
}
},
"mail": {
"transport": "Direct"
},
"logging": {
"transports": [
"file",
"stdout"
]
},
"process": "systemd",
"paths": {
"contentPath": "/var/www/ghost/content"
}
}
Finally, I was able to fix this issue.
It seems that nginx wasn’t restarting correctly so I had to stop nginx with the command sudo systemctl stop nginx
and start it again using sudo systemctl start nginx
to try different configurations and see if those finally worked.
The location /blog configuration on my NGINX config file that worked is the following:
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Update &http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://localhost:2368;
}
And the following is my config.production.json file that worked:
{
"url": "https://tinymentions.io/blog",
"server": {
"port": 2368,
"host": "127.0.0.1"
},
"database": {
"client": "mysql",
"connection": {
"host": "localhost",
"user": "hidden",
"password": "hidden",
"database": "hidden"
}
},
"mail": {
"transport": "Direct"
},
"logging": {
"transports": [
"file",
"stdout"
]
},
"process": "systemd",
"paths": {
"contentPath": "hidden"
}
}