Change Port if needed

in program.cs

webBuilder.UseStartup<Startup>().UseUrls("http://*:5100");

Publish app

Build -> Publish

image

Copy app to server

In home-dir create "myApp" folder

and copy content of "Publish" folder

Test

dotnet myApp.dll

Configure reverse-proxy

For Nginx

/etc/nginx/{your_config}

server {
    listen        80;
    server_name   your_domain *.your_domain;
    location / {
        proxy_pass         http://localhost:5200;
        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;
    }
}

 server {
    listen 443;
    server_name your_domain

    ssl_certificate           /etc/letsencrypt/live/{your_domain}/fullchain.pem;
    ssl_trusted_certificate   /etc/letsencrypt/live/{your_domain}/fullchain.pem;
    ssl_certificate_key       /etc/letsencrypt/live/{your_domain}/privkey.pem;

    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    gzip  on;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/plain text/html text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
    gzip_buffers 16 8k;
    gzip_disable “MSIE [1-6].(?!.*SV1)”;

    access_log  /var/log/nginx/{appname}.access.log;

location / {
    proxy_pass         http://localhost:5200;
    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;
    }
}

Run as service

/etc/systemd/system/{your_app}.serice

[Unit]
Description={your app}

[Service]
WorkingDirectory=/home/{your_user}/{your_app_folder}
ExecStart=/usr/bin/dotnet /home/{your_user}/{your_app_folder}/{your_app_dll}
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-batnikappOC
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

Start service

Start command:

sudo service 'your_app'.serice start

Autostart service

Check status for all

systemctl list-units --type service --all

Check service status

systemctl is–enabled <service_name>

Add service to autostart

systemctl enable <service_name>

Remove service from autostart

systemctl disable <service_name>

enjoy


Создано: 13/10/2021 13:10, Изменено: 15/10/2021 15:25, Просмотров: 28
Назад