(332) 331-8677

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   domain.com www.domain.com;
    location / {
        proxy_pass         http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection $http_connection;
        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=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
RestartSec=10
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