node.js - 在 Centos 7 上配置 Nginx 运行 Nodejs

标签 node.js nginx centos7 droplet

我正在我的centos 7上安装nodejs和nginx。我的应用程序在my_domain:3000上运行正常,但在my_domain.com上出现错误,并显示消息您正在查找的页面暂时不可用。请稍后再试。这是我的 nginx.conf。请帮忙 nginx.conf

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  digitaloceantwo.25o2.in;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        proxy_pass http://digitaloceantwo.25o2.in:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

hello.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080,'159.65.150.176');
console.log('Server running at http://digitaloceantwo.25o2.in:8080/');

最佳答案

我在使用 Fedora 20、Nginx、Node.js 和 Ghost(博客)时遇到了类似的问题。事实证明我的问题是由于 SELinux 造成的。

这应该可以解决问题:

setsebool -P httpd_can_network_connect 1 细节 我检查了 SELinux 日志中的错误:

sudo cat/var/log/audit/audit.log | grep nginx | grep 被拒绝 并发现运行以下命令解决了我的问题:

sudo cat/var/log/audit/audit.log | grep nginx | grep 拒绝 | audit2allow -M mynginx sudo semodule -i mynginx.pp 引用文献:

http://blog.frag-gustav.de/2013/07/21/nginx-selinux-me-mad/

https://wiki.gentoo.org/wiki/SELinux/Tutorials/Where_to_find_SELinux_permission_denial_details

http://wiki.gentoo.org/wiki/SELinux/Tutorials/Managing_network_port_labels

http://www.linuxproblems.org/wiki/Selinux

关于node.js - 在 Centos 7 上配置 Nginx 运行 Nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52165023/

相关文章:

php - 修改 Nginx 正则表达式,使其仅在某些情况下应用

javascript - 将多个 Promise 传递到 Node JS 渲染中

javascript - 无法从node.js更新mongodb中的文档

javascript - Visual Studio Asp.net core Angular 模板在构建时自动运行测试

centos - 通过脚本安装包

node.js - 如何设置服务器运行 Node.js?

python-2.7 - 在Centos 7上使用python 2.7将gradle添加到PATH变量

javascript - Mongoose - 将用户 _id 保存到不同的架构会更改 ID

php - 找不到PHP Docker供应商Autoload.php

ubuntu - 如何在 Ubuntu 16.04 上使用 Nginx 设置多个 https 虚拟服务器 block ?