简体   繁体   English

node.js和nginx代理设置 - 出了点问题,但是什么?

[英]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. 所以我使用这个stackoverflow的答案尝试设置我的本地(在osx上)nginx服务器,让我的node.js网站成功发布到127.0.0.1:3000,以便在我的浏览器中出现在my_url.org。 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) 这是我的nginx服务器:我已经在nginx.conf文件中直接尝试了这个,并且作为我在sites-available文件夹中创建的单独文件,然后创建了指向启用站点的文件夹的链接(根据上面链接的答案) )

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 我知道节点正在运行,因为我可以在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. 我知道nginx.conf文件设置正确,因为: sudo nginx -t告诉我,我在nginx.conf文件中有一个单独的服务器在端口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. 当我访问my_url.org时,我看到托管该站点的远程服务器。 Not 127.0.0.1:3000. 不是127.0.0.1:3000。
  5. after every change I sudo nginx -s reload . 每次更改后我都会sudo nginx -s reload
  6. I've tried both listen 80; 我试过listen 80; and listen 0.0.0.0:80 with equal lack of success. 并且listen 0.0.0.0:80同样缺乏成功。
  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/*; 当我在链接的网站启用文件夹中使用上面的代码尝试此操作时,我的行include /usr/local/etc/nginx/sites-enabled/*; in the nginx.conf file. 在nginx.conf文件中。 When I have the above code in the nginx.conf file, I comment that line out. 当我在nginx.conf文件中有上述代码时,我会注释掉该行。

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 ). 你应该在你的hosts文件my_url.org指向127.0.0.1(与linux和linux一样,它应该在/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.) (我在评论中回答说,在这里向未来的开发者提出同样的问题。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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