English 中文(简体)
缩略语
原标题:Proxy websocket wss:// to ws:// apache

我用<代码>wsss://连接我的网页。

我发现,有办法利用阿帕奇暴露。

  • wss://domain.com - frontend (Apache)
  • ws://domain.com:9090 - backend plaintext

我的组合:

ProxyPass        /websocket ws://domain.com:9090
ProxyPassReverse /websocket ws://domain.com:9090

This code in apache config will send request from any address ended with /websocket to ws://domain.com:9090 ex: ws://websocket will be ws://domain.com:9090

我还想在<代码>wss://上填写。 例:wsss://websocket 页: 1

它是没有工作的,我在浏览器中发现了这一错误:

failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

这里是否有任何错误? 谢谢。

问题回答

i worked 24 hours for find this and searched a lot of forum but no one write about success. here is my server configuration :

CentOS release 6.7 ,harma 4.2.18

here is what i did finally : first i found that modules/mod_proxy_wstunnel.so must be enable in apache config file , but my apache didn t have that module and after a lot of search i found that module is Available in apache 2.4.5 and later.

rel=“noreferer”https://https.d.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html

i downloaded https://archive.apache.org/dist/httpd/httpd-2.4.18.tar.gz extracted httpd-2.4.18modulesproxymod_proxy_wstunnel.c and uploaded to my server root then from terminal could compile it again with these commonds :

chmod 755 mod_proxy_wstunnel.c #set permission
pxs -i -a -c mod_proxy_tunnel.c #compile module

X 指挥系统确实汇编了该单元,并在一个pache config文档中写成装上该单元的

LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

之后,我添加了这些线,以结束藏匿档案:

RewriteEngine on
ProxyRequests Off
ProxyPreserveHost on
ProxyPass /myws ws://mysite.com:8091
ProxyPassReverse /myws ws://mysite.com:8091

AND NOW : it works ! in client side js you can set ws url like this :

var protocol =  ws:// ; 
if (window.location.protocol ===  https: ) {
            protocol =  wss:// ;
   }

 var wsUri =protocol+ "mysite.com/myws";  

 var ws = new WebSocket(wsUri);

and it will forward request to ws://mysite.com:8091 doesnt matter the page loaded with https or http , it will direct all request ended with /myws to ws://mysite.com:8091

你们需要使一些阿帕奇模块能够:

$ a2enmod proxy proxy_wstunnel proxy_http rewrite

然后,你可以利用这一组合解决你的问题。

    ProxyRequests off
    ProxyVia on      
    RewriteEngine On

    RewriteEngine On
    RewriteCond %{HTTP:Connection} Upgrade [NC]
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteRule /(.*) ws://example.com:9090/$1 [P,L]

    ProxyPass               /websocket http://example.com:9090/websocket
    ProxyPassReverse        /websocket http://example.com:9090/websocket

阿帕奇2自动提升了与W ws(https://)的网络链接,你无需人工定点。 我尝试了数十个组合,这是为我工作的唯一组合。

我试图解决的问题与这一问题类似。 我有一个反向的代理机构,即7世纪半衰期的阿帕帕帕帕帕帕特,必须同时与https和ws的要求合作。

在反向代理之后,我有我的服务器在内部网络上运行。 a/etc/httpd/httpd.虚拟东道配置。 conf:

<VirtualHost *:443>
   ServerName example.com
   RewriteCond %(HTTP:Upgrade) websocket [NC]   # Required to handle the websocket connection
   RewriteCond %(HTTP:Connection) upgrade [NC]
   RewriteRule /(.*) ws://192.160.0.1/$1 [P,L]

  SSLEngine on # SSL Certificates handling
  SSLCertificateFile ssl/cert.pem # Public Certificate
  SSLCertificateKeyFile ssl/key.pem # Private certificate
  SSLCertificateChainFile ssl/ca.pem # CA or chain certificate

 ProxyPreserveHost On
 ProxyPass /websocket ws://192.168.0.1 # First you need to write the specific rules
 ProxyPassReverse /websocket ws://102.168.0.1
 ProxyPass / http://192.168.0.1 # Then the generic rules for the proxy.
 ProxyPassReverse / http://192.168.0.1
 </VirtualHost>

在你的情况下,你必须替换服务器Name、SSL证书所在地和代理目的地。

wss needs following module Uncomment line at the httpd.conf of apache conf LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

您的ProxyPass配置道路上没有网路。

使用:

ProxyPass /websocket ws://example.com:9090/websocket
ProxyPassReverse /websocket ws://example.com:9090/websocket

Additional information: Like others mentioned, you have to uncomment the line:

Load Module proxy_wstunnel_module 模块/模块/模块-proxy_wstunnel.so

如果你也使用一条“/”相对途径的“ProxyPas”(直接指所有物品),则必须首先配置具体的“/websocket”路面组合,否则“/”。

ProxyPass /websocket ws://example.com:9090/websocket
ProxyPassReverse /websocket ws://example.com:9090/websocket

ProxyPass balancer://ac-cluster/
ProxyPassReverse / http://example.com:9090

I did it for aria 2. I just enabled some modules and added a single line to config. (env: debian buster/apache 2.4). enabling modes:

sudo a2enmod proxy proxy_balancer proxy_wstunnel proxy_http

在虚拟东道方指令中添加这一条线,以便点燃:

ProxyPass /jsonrpc ws://127.0.0.1:6888/jsonrpc

采用<代码><Location>区块的另一种做法是,配置缩短,可读性提高。

如果你想要一名前线网络服务器,并(与阿帕奇·吉普丁斯一道)支持吉斯蒂尔方案,以替代方式要求一个基本背后网络服务器在通俗文字上:

#
# https://example.com/websocket   -> [Apache:443] -> Websocket plaintext -> [Backend websocket:9000]
# https://example.com/other-stuff -> [Apache:443] -> HTTP      plaintext -> [Backend webserver:8080]
#
<VirtualHost *:443>
    ServerName example.com

    DocumentRoot /var/www/html

    # My application without websocket (if you have that)
    <Location />
        # This can be a Docker container, PHP-FPM, Tomcat, etc.
        ProxyPass        http://localhost:8080/
        ProxyPassReverse http://localhost:8080/
    </Location>

    # Plaintext websockets handled by their dedicated path
    <Location /websocket>
        ProxyPass ws://localhost:9090/
    </Location>

    SSLEngine on
    SSLCertificateFile      ssl/cert.pem # Public Certificate
    SSLCertificateKeyFile   ssl/key.pem  # Private certificate
    SSLCertificateChainFile ssl/ca.pem   # CA or chain certificate

</VirtualHost>

这个例子还试图表明如何把你的吉大港山区应用网与你的网站目录结合起来,因为这是一个经常的问题。

How and Why it works

本文提及正式文件的部分内容:

在一栏内使用时,删除了第一个论点,并从地方名录获得。

——

又注意到你很可能不需要任何<代码>。 网址上的ProxyPasReverse,因为从理论上讲,它没有意义。

又注意到通常你需要写上<编码>ProxyPass ws:// localhost:9090/。 页: 1 或者说,由于网络服务器通常没有位置。

这一答复至少在阿帕奇/2.4.6有用,但可能在其他版本中有用。

Troubleshooting

如果没有工作,就搜寻阿帕奇·吉德里特德网络服务器的错误记录。 这确实值得专门研究,不能在这里加以澄清。

想弄清问题,看看你是否与整个轴有问题,或仅仅与网页有问题。

如果它帮助一些人避免浪费时间和精力的话,我也愿意这样做。

我在研究所有问题后退学。 我准备开始遵循不同的代用单元的代码,我知道,这是一个星号......,但我绝望。 作为最后的资源,我安装了丝网,准确跟踪我网络上正在发生的情况。 在安装电线后,指示要求我通过电离/电离周期重新启用我的服务器。 因此,我这样做了。 当我开始追查时,我完全感到惊讶的是,服务器完全照搬了轮椅要求,没有问题! 因此,我有正确的开端,但在乌班图20.4 /帕帕奇2.4.41 / node 14.17.2 ,需要完全重新启用服务器运行的机器。 !! 但正是......





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签