3

I am new to nginx and I'm struggling to get my configuration for a reverse proxy working. I have a node app running on localhost:3010 and I'm trying to serve pages through nginx from this app at the subdomain dev.[sitename].org. Let's just say dev.example.org for readability. Here are the contents of a file I created in sites-available called example.org (is that the correct name for this file?):

server {
    server_name www.example.org example.org;
}

upstream app_dev.example.org {
    server 127.0.0.1:3010;
}

server {
    listen 0.0.0.0:80;
    server_name dev.example.org;
    access_log /var/log/nginx/dev.example.access.log;
    location / {
            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://app_dev.example.org/;
            proxy_redirect off;
    }
}

This is mostly based off this related question: Node.js + Nginx - What now? however when I try to open dev.example.org in my browser, Chrome reports that it can't find the page. I can ping dev.example.org and get an IP address, so the server seems to be available, but my nginx configuration incorrect. I created the symlink in sites-enabled and restarted nginx, in case you thought I might have forgotten those steps.

So my thought now is that I'm not referring to the subdomain correctly somewhere, or maybe my file in sites-available is named wrong. Any push in the right direction would be appreciated.

Community
  • 1
  • 1
John
  • 401
  • 6
  • 13
  • Have you tried removing the first `server` section, it looks redundant to me. – MGP Jan 27 '14 at 19:40
  • did you reload nginx settings ? `sudo service nginx reload` – Mohammad AbuShady Jan 27 '14 at 19:42
  • I just tried removing the first server section, with no change in behavior. I also just tried reloading nginx (I have been using /etc/init.d/nginx restart after making config changes - is reloading what I should be doing instead?) but that did not seem to have an effect either. – John Jan 27 '14 at 19:47

2 Answers2

1

Just to be sure the problem is on nginx try these steps:

Set a test server at port 3030, serving the system doc folder or anything else.

server {
    listen 3030
    location / {
     root /usr/share/doc/;
     autoindex on;
    }
}

upstream simple_test {
    server 127.0.0.1:3030
}

Then use simple_test below as well:

proxy_pass http://simple_test/;

If you see the /usr/share/doc dir listing when you access dev.example.org then your issue is on the node side.

MGP
  • 2,981
  • 35
  • 34
  • I just tried this, the web browser still results in "could not connect to dev.example.org". – John Jan 27 '14 at 20:29
1

Turned out something was blocking port 80! fixed that and the config as posted above worked

John
  • 401
  • 6
  • 13
  • Glad it's ok. In these cases a `netstat -tapn` could help to know which services are listening on the host. – MGP Jan 27 '14 at 22:01