【发布时间】:2020-06-05 02:04:33
【问题描述】:
来自 Nginx 服务的 Blazor WebAssembly 应用程序的此请求返回 405 Method Not Allowed 错误 (POST):
研究我发现当 Nginx 作为反向代理工作时,需要升级标头,但我的情况不是这样。这里的 Nginx 用作 Web 服务器。这是我的 nginx.conf:
events {}
http {
include mime.types;
types {
application/wasm wasm;
}
server {
listen 80;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html =404;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
add_header 'Access-Control-Allow-Headers' 'Content-Type, X-Requested-With';
add_header 'Access-Control-Allow-Credentials' 'true';
}
}
}
这是我的后端 api 启动配置:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSignalR();
services.AddCors(options =>
{
options.AddDefaultPolicy(builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed(host => true);
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/chatHub");
endpoints.MapControllers();
});
}
我在这里缺少什么?我是否必须在 nginx.conf 中映射特定位置“/chatHub”才能以某种方式使用 webSockets?
Ps.:我正在使用 Docker 容器(docker-compose)。
【问题讨论】:
标签: docker asp.net-core nginx blazor asp.net-core-signalr