SignalR Core Apache WS意外响应代码:200
我目前正在Ubuntu Apache web服务器上运行一个带有Signal的.Net核心应用程序。此.Net核心应用程序可通过example.com/api路径访问 我还有一个Vue JS应用程序也在Web服务器上运行。当我尝试建立到信号器应用程序的websocket连接时,出现以下错误: WebSocket连接到'wss://example.com/api/mainHub?id=V3XZrhdsQDTTMIZvQ-8cbQ'失败:WebSocket握手期间出错:意外响应代码:200 错误:无法启动传输“WebSocket”:null .Net核心应用程序的Apache配置如下所示:SignalR Core Apache WS意外响应代码:200,signalr,apache2,kestrel-http-server,asp.net-core-signalr,kestrel,Signalr,Apache2,Kestrel Http Server,Asp.net Core Signalr,Kestrel,我目前正在Ubuntu Apache web服务器上运行一个带有Signal的.Net核心应用程序。此.Net核心应用程序可通过example.com/api路径访问 我还有一个Vue JS应用程序也在Web服务器上运行。当我尝试建立到信号器应用程序的websocket连接时,出现以下错误: WebSocket连接到'wss://example.com/api/mainHub?id=V3XZrhdsQDTTMIZvQ-8cbQ'失败:WebSocket握手期间出错:意外响应代码:200 错误:无
#Main/Desired Path - https://example.com
<VirtualHost *:443>
DocumentRoot /var/www/example.com/dist/spa
ServerName example.com
#SSL Certs
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:!RC4+RSA:+HIGH:+MEDIUM:!LOW:!RC4
SSLCertificateFile /etc/apache2/ssl/example.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
SSLCertificateChainFile /etc/apache2/ssl/example.ca-bundle
#Upgrade Websockets
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule /(.*) ws://localhost:5000/$1 [P]
#Other specific directories
ProxyPreserveHost On
ProxyPass "/api" http://localhost:5000
ProxyPassReverse "/api" http://localhost:5000
</VirtualHost>
在建立websocket连接时,
startup.cs
将200响应发送回客户端,或者Apache虚拟主机没有正确升级websocket。在将ASP.NET Core 3.1 Blazor服务器端应用部署到Ubuntu时,我也遇到了此错误18.04运行Apache2的服务器
与此错误相结合,我在尝试从Linux服务器访问静态资源(.css文件、图像和脚本)时也遇到了404错误,但在IIS环境中一切都能正常工作。我还注意到,在发布应用程序时,我的解决方案中WWWRoot文件夹的内容似乎没有复制到linux服务器。我使用FolderProfile发布方法,然后通过SFTP将发布文件夹的内容复制到linux服务器
我对样板文件startup.Configure类(来自VS2019中新的Blazor Server Web App模板)所做的唯一“真正”更改是添加UseForwardHeaders指令,如中所述
我还向应用程序添加了身份验证和授权,但再次强调,整个程序在IIS上运行得非常完美,但一旦测试完成,它需要安装在生产linux服务器上
我的Startup.Configure看起来像:
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
// Enable SyncFusion Community Edition License
Syncfusion.Licensing.SyncfusionLicenseProvider
.RegisterLicense("Key-Removed");
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
// Use Authentication and Authorisation providers in the application
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
此外,在linux端,虚拟主机配置文件如下所示:
#<VirtualHost *:*>
# RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
#</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName www.grafton.internal
ErrorLog ${APACHE_LOG_DIR}labapp_error.log
CustomLog ${APACHE_LOG_DIR}labapp_access.log common
</VirtualHost>
#
#RequestHeader集合“X-Forwarded-Proto”expr=%{REQUEST_SCHEME}
#
代理主机
ProxyPass/http://127.0.0.1:5000/
ProxyPassReverse/http://127.0.0.1:5000/
服务器名www.grafton.internal
ErrorLog${APACHE_LOG_DIR}labapp_error.LOG
CustomLog${APACHE_LOG_DIR}labapp_access.LOG公共
注意我已经注释掉了前3行,因为我无法使这个表达式正常工作-Apache无法从我尝试的第2行的每个变体开始。我相信这可能与我的问题有关,但我不确定该怎么办
我还想强调,此应用程序仅供内部使用,web服务器仅在我们的内部网上可见-没有外部/面向internet的服务器或站点,通过物理访问服务器的权限仅限于极少数人,并且限制了固定IP地址,因此我根本不关心使用SSL
如果您有任何帮助,我们将不胜感激。我已经试着让它运行一周了,只剩下一周的时间了,它必须在linux测试环境中运行。我在一个网站()上找到了它,它似乎也适合我。 给定站点的apache配置应该如下所示
<IfModule mod_ssl.c>
<VirtualHost *:443>
RewriteEngine On
ProxyPreserveHost On
ProxyRequests Off
# allow for upgrading to websockets
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:5000/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:5000/$1 [P,L]
ProxyPass "/" "http://localhost:5000/"
ProxyPassReverse "/" "http://localhost:5000/"
ProxyPass "/chatHub" "ws://localhost:5000/chatHub"
ProxyPassReverse "/chatHub" "ws://localhost:5000/chatHub"
ServerName site.com
SSLCertificateFile /etc/letsencrypt/live/site.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
这里也有同样的问题。你找到解决办法了吗?
<IfModule mod_ssl.c>
<VirtualHost *:443>
RewriteEngine On
ProxyPreserveHost On
ProxyRequests Off
# allow for upgrading to websockets
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:5000/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:5000/$1 [P,L]
ProxyPass "/" "http://localhost:5000/"
ProxyPassReverse "/" "http://localhost:5000/"
ProxyPass "/chatHub" "ws://localhost:5000/chatHub"
ProxyPassReverse "/chatHub" "ws://localhost:5000/chatHub"
ServerName site.com
SSLCertificateFile /etc/letsencrypt/live/site.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
a2enmod proxy
a2enmod proxy_wstunnel