I have create a web app and ghost blog. Web app is running on port 80 and ghost blog on 2368 (default for ghost).
I want to add blog page in mydomain/blog. Can anyone help me out with this.
I am able to run the blog on port 80 using nginx but how to run it on particular route of our web app.
this is config file of nginx
server {
listen 3333;
server_name localhost;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:1337;
}
location /blog {
rewrite ^/blog(.*) /$1 break;
proxy_pass http://127.0.0.1:2368;
}
}
My app which is hosted on port 1337 is working fine on 3333 nginx link but when i am opening localhost:3333/blog then blog is not coming properly. it text is coming but its totally distorted seems link css is missing.
So I have two issues regarding this
1. How to host blog properly on mydomain/blog which is localhost:3333/blog in this case.
2. When i am trying to open any page (in spite of its looking distorted) then since that particular route is not found in our main app hence it redirects them to home page?
I have finally able to run it so i am going to answer it here
Lets suppose i have a app and a blog. I have run the app on example.com and blog on example.com/blog
1. App related setting
Lets say you app is running on port 1337.
2. Install ghost properly
a. you can use this link to install ghost.
b. change url of config file of ghost to http://example.com/blog
c. restart the ghost.
npm start --production
or
NODE_ENV=production forever start index.js
3 Install nginx properly
a. you can use this link to install nginx.
b. now create example.conf file in /etc/nginx/site-enabled folder.
server {
listen 80;
server_name example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:1337;
}
location ^~ /blog {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:2368;
proxy_redirect off;
}
}
c. restart the nginx service.
sudo service nginx restart