NewCode CLOUD — 20% off your first month on all cloud VPSClaim

Deploy ASP.NET Core on Hong Kong VPS: .NET 9 for Asia-Pacific (2026)

· 3 min read

ASP.NET Core is Microsoft’s open-source, cross-platform web framework — and with .NET 9’s Ahead-of-Time (AOT) compilation and native Linux support, it’s a first-class citizen on any Hong Kong VPS. Deploying .NET 9 on Ubuntu gives Asia-Pacific enterprises familiar C# tooling with sub-50ms TTFB to mainland China via CN2 GIA, native PostgreSQL access via EF Core or Dapper, and startup times under 200ms without a managed application server.


Step 1: Install .NET 9 Runtime

<code">wget https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

apt update
apt install -y aspnetcore-runtime-9.0

dotnet --info  # Verify

Step 2: Application Configuration

<code"># appsettings.Production.json
{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://127.0.0.1:5000"
      }
    },
    "Limits": {
      "MaxConcurrentConnections": 1000,
      "MaxRequestBodySize": 10485760,
      "KeepAliveTimeout": "00:02:00",
      "RequestHeadersTimeout": "00:00:30"
    }
  },
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=myapp_db;Username=myapp_user;Password=DbPass!;Pooling=true;MinPoolSize=2;MaxPoolSize=20;"
  },
  "Redis": {
    "ConnectionString": "localhost:6379,password=RedisPass!"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}

Step 3: Minimal API with EF Core

<code"># Program.cs — .NET 9 Minimal API
var builder = WebApplication.CreateBuilder(args);

// Services
builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddStackExchangeRedisCache(options =>
    options.Configuration = builder.Configuration["Redis:ConnectionString"]);

builder.Services.AddOutputCache(options => {
    options.AddBasePolicy(p => p.Expire(TimeSpan.FromSeconds(60)));
    options.AddPolicy("products", p => p.Expire(TimeSpan.FromMinutes(5)));
});

builder.Services.AddHealthChecks()
    .AddNpgSql(builder.Configuration.GetConnectionString("DefaultConnection")!)
    .AddRedis(builder.Configuration["Redis:ConnectionString"]!);

var app = builder.Build();

app.UseOutputCache();

// Endpoints
app.MapGet("/health", async (HealthCheckService hc) => {
    var result = await hc.CheckHealthAsync();
    return result.Status == HealthStatus.Healthy
        ? Results.Ok(new { status = "healthy" })
        : Results.StatusCode(503);
});

app.MapGet("/api/products", async (AppDbContext db, IOutputCacheStore cache) => {
    return await db.Products
        .Where(p => p.Active)
        .OrderByDescending(p => p.CreatedAt)
        .Take(20)
        .Select(p => new { p.Id, p.Name, p.Price, p.Category })
        .ToListAsync();
})
.CacheOutput("products");

app.MapPost("/api/products", async (CreateProductRequest req, AppDbContext db) => {
    var product = new Product {
        Name = req.Name,
        Price = req.Price,
        Category = req.Category,
        Active = true,
    };
    db.Products.Add(product);
    await db.SaveChangesAsync();
    return Results.Created($"/api/products/{product.Id}", product);
})
.WithRequestValidation<CreateProductRequest>();

app.Run();

Step 4: Publish Self-Contained Binary

<code"># Publish as a self-contained, trimmed binary (no .NET runtime required on server)
dotnet publish -c Release \
  -r linux-x64 \
  --self-contained true \
  -p:PublishSingleFile=true \
  -p:PublishTrimmed=true \
  -o ./publish

ls -lh ./publish/MyApp
# MyApp  ~30-80 MB — single binary, starts in <100ms

# Copy to VPS
scp -r ./publish root@VPS_IP:/opt/myapp/
chmod +x /opt/myapp/MyApp

Step 5: Systemd Service

<code">useradd -m -s /sbin/nologin dotnet-app
chown -R dotnet-app:dotnet-app /opt/myapp

cat > /etc/systemd/system/myapp.service << 'EOF' [Unit] Description=ASP.NET Core Application After=network.target postgresql.service [Service] Type=notify User=dotnet-app WorkingDirectory=/opt/myapp ExecStart=/opt/myapp/MyApp Restart=always RestartSec=10 KillSignal=SIGINT SyslogIdentifier=myapp Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false EnvironmentFile=/opt/myapp/.env # Security NoNewPrivileges=yes PrivateTmp=yes ProtectSystem=strict ReadWritePaths=/opt/myapp/logs [Install] WantedBy=multi-user.target EOF # /opt/myapp/.env cat > /opt/myapp/.env << 'EOF'
ConnectionStrings__DefaultConnection=Host=localhost;Database=myapp_db;Username=myapp_user;Password=DbPass!
Redis__ConnectionString=localhost:6379,password=RedisPass!
EOF
chmod 600 /opt/myapp/.env

systemctl enable --now myapp
journalctl -u myapp -f

Step 6: Nginx Reverse Proxy

<code">cat > /etc/nginx/sites-available/dotnet << 'EOF'
upstream kestrel { server 127.0.0.1:5000; keepalive 64; }

server {
    listen 443 ssl http2;
    server_name api.yourdomain.com;
    ssl_certificate /etc/letsencrypt/live/api.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.yourdomain.com/privkey.pem;

    location /health { proxy_pass http://kestrel; }

    location / {
        proxy_pass http://kestrel;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Connection "";
    }
}
EOF
ln -s /etc/nginx/sites-available/dotnet /etc/nginx/sites-enabled/
certbot --nginx -d api.yourdomain.com
nginx -t && systemctl reload nginx

Step 7: Migrations and Database Setup

<code"># On the VPS — run migrations
/opt/myapp/MyApp migrate   # If you added a custom CLI command

# Or run migrations via a separate migration binary
dotnet ef migrations add InitialCreate --project MyApp.csproj
dotnet ef database update --connection "Host=localhost;..."

# Automated migrations on startup (recommended for small teams):
# In Program.cs, before app.Run():
using (var scope = app.Services.CreateScope())
{
    var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
    await db.Database.MigrateAsync();
}

.NET 9 Performance on HK VPS

Metric .NET 9 (AOT) Node.js (PM2 cluster) Python FastAPI
Startup time <100ms ~500ms ~800ms
Memory (idle) ~60 MB ~80 MB/worker ~50 MB/worker
Throughput (req/sec, 2 vCPU) 30,000–80,000 20,000–40,000 8,000–20,000
p99 latency (local DB) <5ms <8ms <15ms

Conclusion

ASP.NET Core on a Hong Kong VPS gives .NET teams a production-grade deployment without Windows licensing or IIS — a self-contained binary managed by systemd, proxied through Nginx, with EF Core connecting to local PostgreSQL and Redis for session cache. .NET 9’s AOT compilation produces binaries that start in under 100ms and handle 30,000+ requests per second on a 2 vCPU VPS, making it one of the highest-throughput web frameworks available. CN2 GIA routing delivers API responses to mainland Chinese enterprise customers at 30–60ms — matching what they’d experience from a local cloud provider.

Run .NET in Asia-Pacific: Browse Server.HK Hong Kong VPS plans — a 4 GB plan handles ASP.NET Core with PostgreSQL and Redis comfortably for most enterprise API workloads.

Related articles

More in VPS & ServersServer setup guides