[英]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: 一些线索:
sudo nginx -t
tells me so and I have a seperate server within the nginx.conf file coming through correctly on port 8080. sudo nginx -t
告诉我,我在nginx.conf文件中有一个单独的服务器在端口8080上正确通过。 sudo nginx -s reload
. sudo nginx -s reload
。 listen 80;
listen 80;
and listen 0.0.0.0:80
with equal lack of success. listen 0.0.0.0:80
同样缺乏成功。 include /usr/local/etc/nginx/sites-enabled/*;
include /usr/local/etc/nginx/sites-enabled/*;
in the nginx.conf file. 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.