【问题标题】:Wildlfy with Nginx not working properly带有 Nginx 的 Wildfly 无法正常工作
【发布时间】:2017-11-25 13:18:20
【问题描述】:

我们已经安装了wildfly 几次,它们都能正常工作。我们现在将 Nginx 配置为 Wildfly 的反向代理。

我们正在使用OPTIONS 方法405 Method Not Allowed。这里是nginx的配置。

  • /etc/nginx/conf.d/wildfly.conf

    upstream wildfly {
         server 127.0.0.1:8081;
    }
    
    server {
        listen 8080;
        server_name guest1;
    
        location/ {  
            proxy_pass http://wildfly;
         }
    }
    
    • 安装nginx后报错:

这是nginx得到的错误:

2017/06/23 08:16:54 [crit] 1386#0: *9 connect() 到 127.0.0.1:8081 连接到上游时失败(13:权限被拒绝),客户端:172.28.128.1,服务器:guest1,请求:“OPTIONS /commty/cmng/users HTTP/1.1”,上游:“http://127.0.0.1:8081/commty/cmng/users”,主机:“guest1:8080”

我错过了什么?

【问题讨论】:

  • nginx 日志是怎么说的?它会将选项请求转发给wildfly吗?根据您的照片,我们无法说。此外,wildfly 如何处理对 url commty/cmgt/users 的请求?你那里有休息端点或 servlet 吗?
  • 对不起,我现在无法回答。我有休息端点。我用 nginx 错误日志更新了答案。
  • 好的,现在你的 Wildfly 日志呢? nginx 是否设法通过它?如果是的话,你会说什么。如果没有,尝试检查SElinux是否启用,尝试运行sudo cat /var/log/audit/audit.log | grep nginx | grep denied
  • wildfly 上没有任何内容。审计也一样。我唯一能看到的地方是/var/log/nginx/error.log。如果我尝试正常访问(例如,使用 guest1:8080 访问),我可以看到 Wildfly 默认网页并且一切正常。如果我尝试 guest1:8080/commty/cmng/users 它不起作用
  • 在审核中我发现了这条消息: type=AVC msg=audit(1498207468.887:68): avc: denied { name_connect } for pid=876 comm="nginx" dest=8081 scontext=system_u:system_r :httpd_t:s0 tcontext=system_u:object_r:transproxy_port_t:s0 tclass=tcp_socket

标签: nginx wildfly


【解决方案1】:

我已完成以下操作,最终使其在 CentOS7 + Wildfly 上运行。

  • 流浪起来

  • 安装 NGINX

    • yum install epel-release
    • yum 安装 nginx
  • 配置/etc/nginx/nginx.conf(默认配置)

  • 配置/etc/nginx/conf.d/wildfly.conf(nginx使用80端口,wildfly使用8080端口)

    upstream wildfly {
        server 127.0.0.1:8080;
    }
    
    server {
        listen 80;
        server_name guest1;
    
        location / {  
            proxy_pass http://wildfly;
         }
    }
    

同时设置 SELinux permissive 让 nginx 工作。

$ setenforce permissive

在wildfly通过nginx正常工作之后。

【讨论】: