3

So I used this stackoverflow answer to try and set up my local (on osx) nginx server to have my node.js site that is getting successfully published to 127.0.0.1:3000 to appear at my_url.org in my browser. It isn't working.

Here is my nginx server: I've tried this both in the nginx.conf file directly and as a separate file which I created in the sites-available folder and then created the link to the sites-enabled folder (per the answer linked above)

upstream app_name {
    server 127.0.0.1:3000;
     keepalive 8;
}
server {
    listen 0.0.0.0:80;
    server_name my_url.org my_url;
    access_log /usr/local/var/log/nginx/my_url.org.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_name/;
           proxy_redirect off;
    }
 }

Some clues:

  1. I know the node is working because I can see the code at 127.0.0.1:3000
  2. I know the nginx.conf file is set up correctly because: sudo nginx -t tells me so and I have a seperate server within the nginx.conf file coming through correctly on port 8080.
  3. So far any error logs are blank or non-existent.
  4. when I go to my_url.org I see the remote server on which the site is hosted. Not 127.0.0.1:3000.
  5. after every change I sudo nginx -s reload.
  6. I've tried both listen 80; and listen 0.0.0.0:80 with equal lack of success.
  7. When I try this with the above code in the linked sites-enabled folder, I have the line include /usr/local/etc/nginx/sites-enabled/*; in the nginx.conf file. When I have the above code in the nginx.conf file, I comment that line out.

I'm assuming I'm missing something obvious but missing it I am. Any help wildly appreciated.

Community
  • 1
  • 1
tugboat
  • 67
  • 1
  • 6
  • Yes, when I do that it totally works -- THANK YOU. LIKE, REALLY THANK YOU. I hadn't done that because I kind of assumed (from using MAMP which does that automatically) that I didn't have to. But clearly I do and I hadn't thought of that and I am very grateful. Thank you, Duane. – tugboat Feb 01 '16 at 00:49
  • Haha, Glad it helped! I was a bit over my head, so I wasn't sure if that was the answer. – Duane Feb 01 '16 at 01:00

1 Answers1

2

You should have to point my_url.org to 127.0.0.1 in your hosts file (with linux and linux-like it should be in /etc/hosts).

Otherwise your browser won't know to redirect to your local server.

(I answered in a comment, moving down here for future devs with same problem.)

Duane
  • 4,460
  • 1
  • 25
  • 27