websockets apache2 不工作

websockets apache2 不工作

我正忙于在我们的反向代理(apache2)上实现 websockets,我们使用 proxypass 将流量重定向到 tomcat,但它不起作用,我们得到 403(在我们的日志中被禁止)

apache虚拟主机文件:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin XXX
    ServerName  XXX

    LogLevel warn
    ErrorLog  ${APACHE_LOG_DIR}/XXX_error.log
    CustomLog ${APACHE_LOG_DIR}/XXX_access.log combined

    ProxyPass / http://localhost:8110/ disablereuse=on

    RewriteEngine on

    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule /(.*) "ws://localhost:8110/$1" [P,L]

    ProxyPreserveHost On
    ProxyAddHeaders On
    RequestHeader set X-Forwarded-Proto "https"

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/XXX/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/XXX/privkey.pem
</VirtualHost>
</IfModule>

如果设置了 nginx 反向代理并且一切正常(我在日志中获得了 websocket 连接),应用程序就可以正常工作,但我没有看到我在 apache2 配置中做错了什么。

nginx 虚拟主机:

server {

        server_name XXX;

## Redirect to tomcat
        location / {
                proxy_pass http://localhost:8110;
                proxy_set_header Host $host;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Origin "";
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Origin' '*'  always;
                add_header 'Access-Control-Max-Age' '3600'  always;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
                add_header 'Access-Control-Allow-Headers' '*' always;
        }

## Listen https
    listen 443 ssl; # managed by Certbot

## Certificates
    ssl_certificate /etc/letsencrypt/live/XXX/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/XXX/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = XXX) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


## Listen http
        listen 80;

        server_name XXX;
        return 404; # managed by Certbot
}

答案1

运行以下命令,启用反向代理所需的模块。

a2enmod proxy
a2enmod proxy_http

在您的配置中也使用这两行。

ProxyPass / http://localhost:8110/
ProxyPassReverse / http://localhost:8110/

检查 apache 日志来查找问题

答案2

感谢您的回答,我添加了最后一行,但 ProxyPass / 已经存在。两个模块都已启用(抱歉缺少信息)。

ProxyPassReverse / http://localhost:8110/

我仍然在日志中看到 403

相关内容