Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top