You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使catgenesim.com请求命中后端端点?解决接口超时问题

问题:接口调用超时,请求未抵达后端

我运营着域名catgenesim.com,前端已配置完成,后端显示运行正常,但调用后端任意接口均会出现超时情况。在Visual Studio中设置了断点,但从未触发,说明请求完全未抵达后端。

Program.cs 代码

using System.Net;
using System.Net.Sockets;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using LettuceEncrypt;

var builder = WebApplication.CreateBuilder(args);

// Configure Kestrel and LettuceEncrypt
builder.WebHost.ConfigureKestrel(kestrel =>
{
    kestrel.ListenAnyIP(49155, portOptions =>
    {
        portOptions.UseHttps(h =>
        {
            h.UseLettuceEncrypt(kestrel.ApplicationServices);
        });
    });
});

// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddLettuceEncrypt();

// Add CORS policy
builder.Services.AddCors(options =>
{
    options.AddPolicy("AllowAll",
        policy => policy.AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());
});

// Configure logging
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.AddDebug();
builder.Logging.AddEventSourceLogger();

builder.WebHost.UseSockets(socketOptions => {
    socketOptions.CreateBoundListenSocket = endpoint => {
        var ip = (IPEndPoint)endpoint;
        var listenSocket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
        if (ip.Address.Equals(IPAddress.IPv6Any))
        {
            listenSocket.DualMode = true;
        }
        listenSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        listenSocket.Bind(endpoint);
        return listenSocket;
    };
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

// Use CORS policy
app.UseCors("AllowAll");

app.UseAuthorization();

app.UsePathBase("/api");

app.MapControllers();

app.Run();

appsettings.json 配置(已隐去邮箱信息)

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://catgenesim.com:5000"
      },
      "Https": {
        "Url": "https://catgenesim.com:5001"
      }
    },
    "LettuceEncrypt": {
      // Set this to automatically accept the terms of service of your certificate authority.
      // If you don't set this in config, you will need to press "y" whenever the application starts
      "AcceptTermsOfService": true,

      // You must specify at least one domain name
      "DomainNames": [ "catgenesim.com" ],

      // You must specify an email address to register with the certificate authority
      "EmailAddress": "EMAIL"
    }
  }
}

运行状态截图

本地运行截图

本地运行截图

补充信息

  • Lightsail实例上的运行截图:
    Lightsail实例运行截图
  • Lightsail路由配置截图:
    Lightsail路由配置截图

内容的提问来源于stack exchange,提问作者slastine

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 03:01:10