简体   繁体   中英

node.js & nginx proxy set up — something is wrong, but what?

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.

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM