Deploy ASP.NET CORE 3.1 On Linux Server Ubuntu 18.04

Persiapan:


1. Install .net Core 3.1
2. Install Nginx / Apache (dalam contoh ini menggunakan Nginx)
3. File Build / Publish ASP
4. Konfigurasi Nginx
5. Membuat Service ASP.Net


Install .Net Core 3.1

sudo apt-get update
sudo apt-get install apt-transport-https sudo apt-get update
sudo apt-get install dotnet-sdk-3.1

Versi .Net bisa ditemukan disini



Install Nginx

sudo apt update
sudo apt install nginx

Setelah terinstall Nginx akan segera Aktif, untuk mengeceknya gunakan perintah berikut:

sudo systemctl status nginx

Build dan publish file ASP





- gunakan Git atau Filezilla untuk mengupload file ke server linux

Konfigurasi Nginx

sudo nano /etc/nginx/sites-available/default

Di section Hostname tambahkan block berikut:

server {
listen 80;
server_name {nama-domain-anda.com};
root /home/apps/contoh-apps/{folder-berisi-file-publish};
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;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

- Simpan, lalu jalankan servicenya pakai perintah berikut:

sudo service nginx start
# or restart it if its already started
sudo service nginx restart

Membuat Service ASP.Net

- Buat file service baru

sudo vim /etc/systemd/system/{nama-service-asp}.service

[Unit]
[Service]WorkingDirectory=/home/apps/contoh-apps
ExecStart=/usr/bin/dotnet /home/apps/contoh-apps/Nama-Package.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
# If you need to run multiple services on different ports set
# the ports environment variable here:
# Environment=ASPNETCORE_URLS=http://localhost:6000[Install]
WantedBy=multi-user.target

- Simpan file dan nyalakan service

sudo systemctl enable {nama-service-asp}.service

- Restart service

sudo systemctl start{nama-service-asp}.service

- Untuk mengecek apakah service sudah berjalan normal, pakai perintah berikut:

sudo systemctl status {nama-service-asp}.service

- Jika service tidak berjalan lancar, gunakan perintah berikut unutk megecek log nya:

sudo journalctl -fu {nama-service-asp}.service

Tidak ada komentar

Diberdayakan oleh Blogger.