我正在使用 .NET Core 3.0.0、Blazor 服务器端、Visual Studio 2019、Windows Server 2016。我在服务器上运行正常,但来自外部服务器的连接出现错误。
我使用 Apache HTTP Web 服务器 2.4 虚拟主机 ( http://httpd.apache.org/docs/2.4/vhosts/ ),文件 httpd-vhosts.conf
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName demo.example.com
ErrorLog ${APACHE_LOG_DIR}webapp1-error.log
CustomLog ${APACHE_LOG_DIR}webapp1-access.log common
</VirtualHost>
在 httpd.conf
中,启用模块: proxy
、 proxy_httpd
、 proxy_wstunnel
和
<VirtualHost *:80>
ServerName demo.example.com
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/demo.example.com [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:5000/$1 [P,L]
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
</VirtualHost>
这个错误
blazor.server.js:1 WebSocket connection to 'ws://demo.xxxx.xx/_blazor?id=LZk17pmIejWGHLkhN3HFmA' failed: Error during WebSocket handshake: Unexpected response code: 200
最佳答案
似乎其他人在代理 Web 套接字连接时遇到问题。在这里为您找到了一个潜在的解决方案:https://github.com/aspnet/Blazor/issues/1882
<VirtualHost *:80>
ServerName www.domain.com
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule /(.*) ws://127.0.0.1:5000/$1 [P]
ErrorLog /.log
CustomLog /.log common
关于asp.net-core - ASP.NET Core 3 Blazor : Run on localhost of server ok, 但在服务器外部运行错误:WebSocket 握手期间出错:意外的响应代码:200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58196221/