- Install Microsoft .NET 8.0 (SDK) using official manual.
- Install NGINX and certbot according to their manuals.
- Clone Git-repo to local folder (for example, to
/home/somebackend
). - Self test:
- Go to
/home/somebackend
folder - Runs
dotnet test
- In 1-2 minutes it should finish with green text like:
Passed! - Failed: 0, Passed: 3, Skipped: 0, Total: 3, Duration: Х ms - backend.tests.dll (net8.0)
- Go to
- Go to
/home/somebackend/backoffice
- Edit
appsettings.json
(put master contract address into MasterAddress, change other params if required) - Build application using
dotnet publish -c Release -o /var/www/somebackend
, where folder after-o
is target folder you want to run app from. - Download tonlib library into app folder:
Make sure you choose correct architecture (
wget https://github.com/ton-blockchain/ton/releases/download/v2024.01/tonlibjson-linux-x86_64.so -o /var/www/somebackend
tonlibjson-linux-arm64.so
ortonlibjson-linux-x86_64.so
) that matches your system. - Create cache folder and set correct permissions:
mkdir /var/www/somebackend/cache & chmod 777 /var/www/somebackend/cache
(this folder will be used to store blockchain sync data, Merkle proofs etc);
Now, you can run the app. Execute /var/www/somebackend/backend
- it will show different logs on screen, including detecting existing admin/user/order contracts. Screen should not have red (error) text.
You may use systemd for starting ap as a service, using this example service description file:
[Unit]
Description=Some Backend
[Service]
WorkingDirectory=/var/www/somebackend
ExecStart=/var/www/somebackend/backend
Restart=always
RestartSec=10
TimeoutStopSec=30
KillMode=process
KillSignal=SIGTERM
SyslogIdentifier=somebackend
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Please ensure values in WorkingDirectory
и ExecStart
matches parameter -o
value during dotnet publish
.
Start/stop service: sudo systemctl start somebackend
and sudo systemctl stop somebackend
.
View logs: sudo journalctl -fu somebackend -n 100
(show last 100 log entries and wait for new ones).
You may configure backend to run on port 80 and expose this port directly, but using Nginx as reverse proxy will give you additional benefits, like HTTPS/SSL certificate management, additional header configuration etc.
Use this sample config when creating new site in Nginx:
server {
listen 80;
listen [::]:80;
server_name somebackend.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;
proxy_set_header X-Real-IP $remote_addr;
}
}
Please use real (external) domain name in server_name
parameter (don't forget to update entry in tour DNS Zone).
Port number in proxy_pass
parameter should math one in Kestrel:Endpoints:Http:Url
in appsettings.json
configuration file.
Use certbot
to create free SSL-certificate and update it automatically.
Done. Now open https://somebackend.example.com/swagger in your browser - you should see Swagger page.