Berbagai Cara untuk Deploy Aplikasi Web Dengan ASP.NET Core

Muhammad Arslan 29 Mei 2017

Berbagai Cara untuk Deploy Aplikasi Web Dengan ASP.NET Core

Ada beberapa pilihan untuk deploy aplikasi web dengan ASP.NET Core.

  • Nginx di Linux dan Unix, Dengan menggunakan kombinasi OWin dan Web server seperti Nginx atau Apache, kamu dapat memasang ASP.NET Core kamu diatas sistem operasi selain Windows Server. Tentunya dengan beberapa konfigurasi pada source code dan diatas server maka kamu dapat memasang ASP.NET Core diatas Linux. Baca selanjutnya di https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction

Contoh konfigurasi pada source code

app.UseForwardedHeaders(new ForwardedHeadersOptions
{
    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

Contoh konfigurasi Nginx untuk ASP.NET Core:

server {
    listen 80;
    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Contoh script untuk service ASP.NET Core diatas Linux:

[Unit]
Description=Example .NET Web API Application running on Ubuntu

[Service]
WorkingDirectory=/var/aspnetcore/hellomvc
ExecStart=/usr/bin/dotnet /var/aspnetcore/hellomvc/hellomvc.dll
Restart=always
RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production 

[Install]
WantedBy=multi-user.target

Contoh cara menjalankan ASP.NET Core sebagai service di Linux:

systemctl start kestrel-hellomvc.service
systemctl status kestrel-hellomvc.service

● kestrel-hellomvc.service - Example .NET Web API Application running on Ubuntu
    Loaded: loaded (/etc/systemd/system/kestrel-hellomvc.service; enabled)
    Active: active (running) since Thu 2016-10-18 04:09:35 NZDT; 35s ago
Main PID: 9021 (dotnet)
    CGroup: /system.slice/kestrel-hellomvc.service
            └─9021 /usr/local/bin/dotnet /var/aspnetcore/hellomvc/hellomvc.dll
  • Apache di Linux dan Unix, Hampir sama dengan Nginx + Linux. Baca selanjutnya di https://docs.microsoft.com/en-us/aspnet/core/publishing/apache-proxy
  • Azure App Service, layanan Azure yang satu ini dapat membuat kamu memasang aplikasi web yang kamu kembangkan tanpa ribet dengan konfigurasi server seperti biasanya. Azure App Service hanya memerlukan Git untuk mengirim source code aplikasi kamu dan akan dijalankan secara otomatis oleh Azure App Service bila ada perubahan. Selain itu Azure App Service juga mendukung scaling yang lebih mudah dibandingkan menggunakan VPS atau hosting biasa. Baca selanjutnya di https://docs.microsoft.com/en-us/aspnet/core/publishing/azure-continuous-deployment
  • Windows Server + IIS, ini merupakan cara klasik dimana kamu dapat men-deploy aplikasi ASP.NET Core sama dengan ASP.NET yang sebelumnya. Dengan sedikit konfigurasi, kamu dapat membuat aplikasi web-mu yang ditulis dengan ASP.NET Core dapat berjalan diatas Windows Server + IIS. Baca selanjutnya di https://docs.microsoft.com/en-us/aspnet/core/publishing/iis
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;

namespace WebApplication1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
    }
}
  • Docker, saat ini adalah era containerization yang digunakan untuk mendukung microservice, tak terkecuali ASP.NET Core, kamu dapat mengemasnya di dalam Docker menjadi bagian dari microservice bersama sistem microservice lain yang sudah kamu kembangkan. Baca lebih lanjut di https://docs.microsoft.com/en-us/aspnet/core/publishing/docker
  • IBM Bluemix, saat ini Bluemix menyediakan juga PaaS untuk ASP.NET Core

(arslan/microsoft)