Deploy .Net Core on Ubuntu with Nginx
ubuntu 20.04 , Net Core 3.1
Install .net core on Ubuntu headless server
command :
sudo apt update && sudo apt upgrade -y
dotnet --version
which dotnet ## Should return something similar too /usr/bin/dotnet
sudo nano /etc/environment
##add the end of the file paste the following
DOTNET_HOME="/usr/bin/dotnet"
Deploy .net core application to AWS Lightsail
Command :
sudo apt-get install nginx
Create your Website folder in Nginx
The default location Nginx creates web folders /var/www/html
root
/var/www
Create a new folder, call it
sudo mkdir /var/www/[webname]
chown ubuntu:ubuntu /var/www/[webname]
sudo nano /etc/nginx/sites-available/default
##Replace the content of this file with:
server {
listen 80;
root /var/www/test/wwwroot;
server_name _;
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 $http_host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
-------------------------------------------------------
sudo nano /etc/systemd/system/[webname].service
##Add the following content
[Unit]
Description=Test .net core website
[Service]
WorkingDirectory=/var/www/test
ExecStart=/usr/bin/dotnet /var/www/test/test.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=ubuntu
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
-------------------------------------------------
sudo systemctl enable [webname].service
sudo systemctl start [webname].service
sudo systemctl status [webname].service
sudo service nginx restart
----------------------------------