提问人:Petar Tahchiev 提问时间:11/5/2023 更新时间:11/7/2023 访问量:29
代理将 websocket 连接传递到另一个端口
Proxy pass websocket connections to another port
问:
所以我安装了 Openfire,并且管理后台在端口 9090 上运行。我正在尝试通过端口 7070 上的 websocket 与 Strophe 连接,所以我在 Nginx 中这样做了:
server {
server_name example.com;
root /var/www/html;
location /ws/server {
proxy_pass http://openfire:7070/ws/server;
# this magic is needed for WebSocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://openfire:9090/;
}
location ~ /.well-known/acme-challenge {
allow all;
root /var/www/html;
}
}
它工作正常。但不幸的是,我必须使用 Apache Http Server 而不是 Nginx,所以现在我需要为 Apache Http 服务器重写这段代码。 这是我的尝试:
GNU nano 5.4 openfire-https-vhost.conf
<VirtualHost 127.0.0.1:443 _default_:443>
ServerName example.com
ServerAlias *
SSLEngine on
SSLCertificateFile "/opt/bitnami/apache/conf/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apache/conf/server.key"
# BEGIN: Configuration for letsencrypt
Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"
# END: Configuration for letsencrypt
# BEGIN: Support domain renewal when using mod_proxy without Location
<IfModule mod_proxy.c>
ProxyPass /.well-known !
ProxyPass /ws/server !
</IfModule>
# END: Support domain renewal when using mod_proxy without Location
<Location />
ProxyPass http://127.0.0.1:9090/
ProxyPassReverse http://127.0.0.1:9090/
</Location>
<Location /ws/server>
RewriteEngine On
ProxyPreserveHost On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:7070/ws/server$1 [P,L]
ProxyPass http://127.0.0.1/ws/server
ProxyPassReverse /
</Location>
# BEGIN: Support domain renewal when using mod_proxy within Location
<Location /.well-known>
<IfModule mod_proxy.c>
ProxyPass !
</IfModule>
</Location>
# END: Support domain renewal when using mod_proxy within Location
</VirtualHost>
但是现在当我尝试通过 Postman 连接时,我在服务器上收到此错误;
2023.11.04 17:49:18 WARN [Jetty-QTP-BOSH-70]: org.jivesoftware.openfire.websocket.OpenfireWebSocketServlet - Failed to create websocket for 127.0.0.1:57752 make a request at /server/127.0.0.1/ws/server
任何人都可以帮我将nginx重写为apache代码。
答: 暂无答案
评论