How to run asp.net core on Linux web server
ssh root@web.server.ip.address
adduser username
usermod -aG sudo username
ssh-keygen
ssh-copy-id username@web.server.ip.address
ssh username@web.server.ip.address
sudo nano /etc/ssh/sshd_config
PasswordAuthentication no
Ctrl+X
Shift+Y
Enter
sudo systemctl restart ssh
sudo apt update
sudo apt install nginx
cd /etc/nginx/sites-available
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/domain.com
sudo nano /etc/nginx/sites-available/domain.com
Ctrl+K
server {
listen 80;
server_name example.com *.example.com;
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;
}
}
sudo ln -s /etc/nginx/sites-available/domain.com /etc/nginx/sites-enabled/
sudo nano /etc/nginx/nginx.conf
server_names_hash_bucket_size 64;
sudo nginx -t
sudo systemctl restart nginx
cd
mkdir domain.com
sudo nano /etc/systemd/system/name.service
[Unit]
Description=Example .NET Web API App running on Ubuntu
[Service]
WorkingDirectory=/home/username/domain.com
ExecStart=/usr/bin/dotnet /home/username/domain.com/ProjectName.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=username
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
sudo systemctl enable name.service
sudo systemctl start name.service
sudo systemctl status name.service
sudo systemctl restart name.service
sudo systemctl daemon-reload
client_max_body_size 100M;
sudo systemctl restart nginx
sudo certbot --nginx
sudo -i
/etc/letsencrypt/live
echo "" > fileForRemoveText.txt