How i run ghost in subdomain ?

January 2, 2014 3.4k views
Hi, this my first time setup ghost blog so i try to put it in subdomain but i don't know how, i use nginx and ubuntu 12.0.4 LTS .. i need it to work in subdomain so i can put another thing in main.. also i have another issue when i type my domain without www it's not work !! you can check http://csbukhari.com/ http://www.csbukhari.com/ help me please
5 Answers
You need to make sure your DNS points www either to an A record or a CNAME record.

As for the subdomain you can do

server {
listen 80;
server_name subdomain.domain.tld

location / {
expires 8d;
proxy_set_header X-Real-IP $remote_addr;
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_set_header X-NginX-Proxy true;
proxy_read_timeout 5m;
proxy_connect_timeout 5m;
proxy_pass http://127.0.0.1:1337;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}


This is just an example, but change the server name and the proxy_pass and it should work fine
my conf file
server {
listen 80;
server_name blog.csbukhari.com;

client_max_body_size 10M;

location / {
proxy_pass http://localhost:2368/;
proxy_set_header Host $host;
proxy_buffering off;
}
}


i do it but i dosent work
I don't see any of csbukhari.com or www.csbukhari.com there, are you sure this is the only config file?
What is this block of code actually doing?

location / {
expires 8d;
proxy_set_header X-Real-IP $remote_addr;
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_set_header X-NginX-Proxy true;
proxy_read_timeout 5m;
proxy_connect_timeout 5m;
proxy_pass http://127.0.0.1:1337;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

Is this in the default.conf file? Or is this the customized config file in the sites-available directory?
@wjhsie:
proxy_set_header X-Real-IP $remote_addr; 

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_set_header X-NginX-Proxy true;
[..]
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
sets the headers nginx should add while proxying the contents to Ghost/nodejs
proxy_read_timeout 5m; 

proxy_connect_timeout 5m;
sets a couple of connection parameters.
proxy_pass http://127.0.0.1:1337; 
sets the server nginx should proxy to (in this case it's a nodejs app that is listening on port 1337 on the loopback interface).

As for the proxy_redirect line, see http://wiki.nginx.org/HttpProxyModule#proxy_redirect.

I hope that helps.
Have another answer? Share your knowledge.