【问题标题】:Nginx forward to tomcat failingNginx 转发到 tomcat 失败
【发布时间】:2017-12-09 20:46:57
【问题描述】:

我试图将我的 nginx 服务器转发到 tomcat(在同一台服务器上)。

我遵循了以下教程:

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-centos-7 https://www.digitalocean.com/community/tutorials/how-to-encrypt-tomcat-8-connections-with-apache-or-nginx-on-centos-7

但它似乎仍然无法正常工作,虽然它在我以前的服务器上可以。

这是我的 nginx 配置

....

Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

upstream tomcat {
server 127.0.0.1:8080 fail_timeout=0;
}

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  mywebsite.be demo.mywebsite.be;
    root         /usr/share/nginx/html;

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

    location / {
       #try_files $uri $uri/ =404;
    proxy_pass http://tomcat/;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    ....

当我重新启动 nginx 并访问我的网站时,我收到以下错误:

“您要查找的页面暂时不可用。请稍后再试。”

当我的 tomcat 服务器在线并工作时。

我不知道出了什么问题,我已经重新安装了几次 nginx 和 tomcat。

nginx 错误日志给出以下错误

2017/12/09 13:33:53 [crit] 1288#0: *73 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to
     upstream, client: 87.**.***.244, server: mywebsite.be, request: "GET / HTTP/1.1", upstream: "http://127.0.0
    .1:8080/", host: "demo.mywebsite.be"

2017/12/09 13:33:53 [crit] 1288#0: *73 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to
 upstream, client: 87.**.***.244, server: mywebsite.be, request: "GET /nginx-logo.png HTTP/1.1", upstream: "
http://127.0.0.1:8080/nginx-logo.png", host: "demo.mywebsite.be", referrer: "https://demo.mywebsite.be/"

2017/12/09 13:33:53 [crit] 1288#0: *74 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to
 upstream, client: 87.**.***.244, server: mywebsite.be, request: "GET /poweredby.png HTTP/1.1", upstream: "h
ttp://127.0.0.1:8080/poweredby.png", host: "demo.mywebsite.be", referrer: "https://demo.mywebsite.be/"

2017/12/09 13:33:53 [crit] 1288#0: *74 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream, client: 87.**.***.244, server: mywebsite.be, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8080/favicon.ico", host: "demo.mywebsite.be", referrer: "https://demo.mywebsite.be/"

【问题讨论】:

  • 如果您的网站正在生成 5xx 响应,则错误日志中应该有相应的消息。
  • 谢谢,我添加了 nginx 错误日志

标签: java tomcat nginx


【解决方案1】:

感谢 Richard Smith 提出错误日志的想法

我已经通过运行以下命令解决了这个问题:

/usr/sbin/setsebool httpd_can_network_connect true

解释如下:

nginx proxy server localhost permission denied

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多