(Docker, Nginx, HTTPS & Production Best Practices)
Writing code is only half the job.
Deployment, security, and reliability decide whether your ASP.NET Core application survives in production.
In this article, we’ll deploy an ASP.NET Core API using Docker, secure it with Nginx + HTTPS, and apply real-world production hardening techniques.
Production Deployment Architecture
Client (Browser / Mobile)
↓ HTTPS
Nginx (Reverse Proxy)
↓
ASP.NET Core (Docker)
↓
Database / CacheWhy Use Docker?
Environment consistency
Easy scaling
Faster deployments
CI/CD friendly
Step 1: Create Dockerfile for ASP.NET Core
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY . .
RUN dotnet restore
RUN dotnet publish -c Release -o out
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/out .
EXPOSE 8080
ENTRYPOINT ["dotnet", "MyApp.dll"]Step 2: Docker Compose Setup
version: "3.9"
services:
api:
image: myapp-api
container_name: aspnet_api
restart: always
ports:
- "8080:8080"
environment:
ASPNETCORE_ENVIRONMENT: ProductionStep 3: Run the Application
docker build -t myapp-api .
docker compose up -dYour API is now running at:
http://localhost:8080Step 4: Nginx as Reverse Proxy
Nginx handles:
SSL termination
Rate limiting
Load balancing
Security headers
Nginx Configuration
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}Step 5: Enable HTTPS (Let’s Encrypt)
Install Certbot
sudo apt install certbot python3-certbot-nginxGenerate SSL Certificate
sudo certbot --nginx -d api.example.com