Vestacp Nginx proxy passing to a node application

March 16, 2015 6.3k views
Nginx Ghost Ubuntu

Hello DO Community, I hope all of you are doing great.

I am facing an issue with nginx proxy passing. So far I have successfully install Ubuntu 14.04 and vestacp panel and they are working great. I can even create sub-domains with no problem.

Now I want to create a ghost blog in a sub-domain (eg blog.main-doimain.com) which by the way runs on node. I have managed to run the ghost blog on port 3000 and i can access it using main-domain.com:3000

To access it via sub-domain I have added following server block on nginx (which is installed by vestacp)

server {
    listen 80;
    server_name blog.main-domain.com;

    root /var/www/ghost;
    index index.html index.htm;

    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}

but still i can't access it.

Then I created a blank droplet, installed ubuntu 14.04, installed nginx (only) then installed ghost in it in the same way and added the above server block. And surprisingly it worked, I could access it like blog.main-domain.com!!!

My question is:

  1. Am I doing something wrong??
  2. Does vestacp & ghost work along side this way or not??
  3. Has anyone tried something like this and succeeded or failed??

Thank you and sorry for really long post.

2 comments
  • On the server with VestaCP, what is the file you are editing with the Nginx configuration? Generally, control panels try to take over most of the system and could potentially overwrite files that you edit manually or load their configuration from non-standard paths.

  • /etc/nginx/conf.d/ghost.conf
    this is the path of my configuration file. from my finding vestacp keeps its configuration setting in this file: /home/admin/conf/web/nginx.conf;
    and that file is included by another one called: /etc/nginx/conf.d/vesta.conf

1 Answer

I was able to solve my problem. I had to make following changes to do so:

in the server block:

    server {
        # previously
        # listen 80; 

        # now
        # here a.b.c.d is my droplet ip
        listen a.b.c.d:80;  

        server_name blog.main-domain.com;

        root /var/www/ghost;
        index index.html index.htm;

        location / {
            # previously
            # proxy_pass http://127.0.0.1:3000;

            # now
            # here a.b.c.d is my droplet ip
            proxy_pass http://a.b.c.d:3000;
        }
    }

and in the ghost blog config file:

    server: {
        host: 'a.b.c.d', /* here a.b.c.d is my droplet ip */
        port: '3000'
    }

and lastly i had to change iptable to accept request on port 3000. that it!

Have another answer? Share your knowledge.