Node.js 应用程序的 Nginx 代理配置问题 [英] Nginx proxy config problems for Node.js app

查看:62
本文介绍了Node.js 应用程序的 Nginx 代理配置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎可以肯定这只是我的无知,并希望这很容易解决,但基本上 mydomain.com:3000 提供正确的内容,但 mydomain.com 没有.这是我的 nginx.conf.default 文件的内容:

I'm almost certain this is just my ignorance and expecting this to be an easy fix, but basically mydomain.com:3000 serves the correct content, but mydomain.com does not. Here is what my nginx.conf.default file has:

upstream mydomain {
    server 127.0.0.1:3000;
    keepalive 8;
}

server {
    listen       0.0.0.0:80;
    server_name  mydomain.com www.mydomain.com;

    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://mydomain/;
        proxy_redirect off;
    }
}

我一直在关注这篇文章,但不知道我的错误在哪里:http://dailyjs.com/2010/03/15/hosting-nodejs-应用程序/

I've been following this article, but can't figure out where my error is: http://dailyjs.com/2010/03/15/hosting-nodejs-apps/

(注意:我相信我的 nginx 安装与此不同,因为没有 sites-available 文件夹.相反,我正在编辑 nginx.conf.default 文件,因为我看到 localhost 服务器的行高于我到了.)

(Note: I believe my installation of nginx differs from this as there is no sites-available folder. Instead, I'm editing the nginx.conf.default file because I saw the lines for the localhost server above the ones I've got here.)

基本上,我想要的是能够访问 mydomain.com 来加载内容,而不是 mydomain.com:3000.

推荐答案

这完全是发行版和软件包的问题,​​而不是 nginx 版本,我之前已经在不同的答案中解释过,主要且唯一重要的文件是 nginx.conf,如果您检查该文件,您将知道哪些文件夹重要,哪些不重要"t,例如 debian 发行版在他们的配置中添加这一行

This is all a matter of distros and packages not nginx versions, I've explained this in a different answer before, the main and the only file that matters is nginx.conf, if you check that file you would know what folders matters and what don't, for example debian distros add this line in their config

include /etc/nginx/sites-enabled/*;

这样,自动包含 sites-enabled 文件夹中的所有文件,
Redhat 发行版只使用这一行

So that auto includes all the files inside the sites-enabled folder,
Redhat distros use this line only

include /etc/nginx/conf.d/*.conf;

顺便说一句,debian 分布式配置中仍然包含此内容,
这意味着只考虑 /etc/nginx/conf.d 中的文件,并且它们必须以 .conf

which is btw still also included in the debian distributed config,
This means that only the files inside /etc/nginx/conf.d are considered, and also they have to end with .conf

只需检查您的 nginx.conf 并确保您的配置位于包含的文件夹中,至于配置本身,它似乎应该可以正常工作.

Just check your nginx.conf and make sure that your config is in an included folder, as for the config it self it seems that it should be working fine.

这篇关于Node.js 应用程序的 Nginx 代理配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆