We going to look at a simple tutorial on how to have your .net core site run on a linux server and make use of supervisor to start up and monitor the site.
First we going to assume you have supervisor installed on the box, with nginx already running.
For the explanation of the above
and thus basically it.
restart start supervisor
Configure supervisor
- firstly browse to the folder /etc/supervisor/conf.d
- Inside this folder create a .conf file for example dotnettest.conf
- Open the dotnettest.conf and insert the following lines
[program:dotnettest]
command=/usr/bin/dotnet /home/testapp/bin/Debug/netcoreapp2.2/publish/testapp.dll
directory=/home/testapp/bin/Debug/netcoreapp2.2/publish/
autostart=true
autorestart=true
stderr_logfile=/var/log/dotnettest.err.log
stdout_logfile=/var/log/dotnettest.out.log
environment=ASPNETCORE_ENVIRONMENT=Production
user=root
stopsignal=INT
command=/usr/bin/dotnet /home/testapp/bin/Debug/netcoreapp2.2/publish/testapp.dll
directory=/home/testapp/bin/Debug/netcoreapp2.2/publish/
autostart=true
autorestart=true
stderr_logfile=/var/log/dotnettest.err.log
stdout_logfile=/var/log/dotnettest.out.log
environment=ASPNETCORE_ENVIRONMENT=Production
user=root
stopsignal=INT
For the explanation of the above
- you specify the name of your site by placing "program:" in front of it
- command you use to specify that you want dotnet which is located in /usr/bin/dotnet of your server to run your application and you provide the full path to your application's dll, in my case it is "/home/testapp/bin/Debug/netcoreapp2.2/publish/testapp.dll"
- directory is used to specify the directory folder of your application
every thing else is more or less standard
Configure Nginx
- browse to /etc/nginx/sites-available
- Open the file default
- Scroll down to the section just below "# Default server configuration"
- Edit it so it looks like below
server {
listen 80;
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;
}
}
The most important thing from the above is the proxy_pass section. In this part you tell nginx to point to the localhost port in which your site is running under. In my case it it localhost:5000listen 80;
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;
}
}
and thus basically it.
restart start supervisor
service supervisor restart
To check the status of supervisor
service supervisor status
This comment has been removed by the author.
ReplyDelete