【问题标题】:Config Nginx running Nodejs on Centos 7在 Centos 7 上配置运行 Nodejs 的 Nginx
【发布时间】:2018-09-04 11:12:53
【问题描述】:

我正在我的 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 {
        }
    }

你好.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/');

【问题讨论】:

  • 你能从Nginx服务器访问nodejs应用吗,你可以通过curl http://digitaloceantwo.25o2.in:8080测试

标签: node.js nginx centos7 droplet


【解决方案1】:

我在让 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

【讨论】:

  • 我一直在寻找这个!非常感谢。
猜你喜欢
  • 1970-01-01
  • 2016-07-25
  • 1970-01-01
  • 2016-01-04
  • 2014-01-23
  • 2010-11-05
  • 2017-06-08
  • 2023-03-14
  • 2017-07-26
相关资源
最近更新 更多