繁体   English   中英

Nginx配置与Node.js一起使用

[英]Nginx configuration to work with Node.js

我知道在这里或在网络中也有类似的问题或演练,尽管我对此感到困惑。

的背景

我试图建立一个本地虚拟主机ghost.local,那里将有一个幽灵博客(位于Node.js上)。 所以我想,当我在Ubuntu 14.04机器上访问http://ghost.local时,Nginx会将请求传递给Node.js,这样我就可以看到我的幽灵博客。

问题

我已经设置了hosts文件,我已经设置了nginx vhosts,我的幽灵正在Node.js上运行。 虽然当我访问http://ghost.local时,我得到了

503服务不可用无法解析服务器ghost.local的名称

我的主机文件:

 127.0.0.1  ghost.local
 127.0.0.1  localhost

我的/etc/nginx/sites-available/ghost.local文件:

 server {
     listen 80;
     server_name ghost.local;
     access_log /var/log/nginx/ghost.local.log;

     location / {        
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-for $remote_addr;
         proxy_set_header HOST $http_host; 

         proxy_pass http://localhost:2368;
         proxy_redirect off;
    }
 }

/etc/nginx/sites-enabled/ghost.local中的链接设置正确。

我没有发布来自ghost或node.js的任何内容,因为在http:// localhost:2368上已启动并且一切正常。

有人知道吗? 谢谢大家。

编辑正如我在评论中提到的那样,问题很可能是在我的机器上设置了在新机器上工作的上述配置。

首先,您似乎安装了错误的nginx版本。 您是否自行安装了它,如果是的话,应该重新安装最新版本的nginx。

其次,如果您的网站位于http://ghost.local上,我会感到困惑。

因为server_name应该是您网站的子/域,所以她是一个示例:

server_name www.example.com example.com test.example.com;

这是位于http://example.com的网站的基本nginx配置

server {
        listen 80;
        server_name example.com;
        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host      $http_host;
                proxy_pass                 http://127.0.0.1:2368;
        }
}

server {
        listen 80;
        server_name www.example.com;
        return 301 http://example.com/$request_uri;
}

确保重新启动Nginx后记。

service nginx restart

暂无
暂无

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

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