DotNet Publish service in ubuntu 18 #DotNet #Ubuntu - ada3000/linux-howto GitHub Wiki
1. Create systemd unit, put into file /etc/systemd/system/my-service-name.service
[Unit]
Description=Example .NET Web API App running on Ubuntu
[Service]
WorkingDirectory=/var/www/my-service-name
ExecStart=/usr/bin/dotnet /var/www/my-service-name/App.dll
Restart=always
##### Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=my-service-name
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
- Enable service "systemctl enable my-service-name"
- Start service "systemctl start my-service-name"
- Stop service "systemctl stop my-service-name"
- View status "systemctl -l status my-service-name"
View logs:
"journalctl -u my-service-name" "journalctl -f -u my-service-name"
Add to Nginx
- Add file to folder /etc/nginx/sites-enabled/my-service-name
server {
server_name my-service-name.domain.root;
location / {
proxy_pass http://localhost:XXX;
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;
}
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
listen 80;
}
- Check nginx config "nginx -t"
- Restart nginx "service nginx restart"
- Add ssl, run in console "certbot"