Note: This test is based on the Deepin Linux system

1, publish,

Release the project file to a directory in Windows. For details, see ASP.Net Core program release.


2. Upload the server

To upload the published project files to the Linux server, use SecureCRT to upload the files to the server. For better understanding, assume that you have uploaded the angularDemo01.tar file to the /usr/publisk/angular path of the server.


3, run,

Open the terminal and upload the directory

cd /usr/publishCopy the code

Grant permissions to uploaded file directories

sudo chmod -R 777 AngularCopy the code

Find the compressed package If the uploaded package is compressed, decompress it first

cd Angular
sudo tar -xvf AngularDemo01.tarCopy the code

Unzip the file and run the project

sudo dotnet AngularDemo01.dllCopy the code

Note: the AngularDemo01) DLL must be released in the DLL files under the directory, such as released by the path for the bin/Release/netcoreapp3.1 / publish /, is the DLL under the publish folder

Open your browser and enter the address to visit

http://localhost:5000Copy the code

If the project is normal, proceed to the next step. Otherwise, handle the exception first

Exception handling reference:

  • The SPA default page middleware can not return the default page “index.html”



4. Reverse proxy

It is now accessible on Linux. If you need to access it under Windows, you can use nginx to reverse proxy.

Install nginx

sudo apt-get install nginxCopy the code

After the installation is successful, start nginx

systemctl start nginxCopy the code

After successful startup, you can set nginx to boot automatically (Linux downtime, restart will automatically run nginx without manually entering the command to start).

systemctl enable nginxCopy the code

The IP address of the Linux operating system can be accessed from the Windows system to test whether nginx is accessible. If the access is normal, you can modify the nginx configuration file to forward ASP.Net Core applications.

Modify/etc/nginx/conf. D/default. The conf file

server {
    listen 80;
    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; }}Copy the code

Execute the following code to reload the nginx configuration file

nginx -s reloadCopy the code

Run the ASP.Net Core application again. At this point, you can access the application directly on your Window.

If the following error occurs:



Possibly due to SELinux protection, add nginx to the SELinux whitelist.

Scheme reference:

  • Deploying ASP.NET Core applications to production (CentOS7)



5. Supervisor

At present, our project is run through the terminal. If the terminal is closed, the program will also stop running, resulting in inaccessible. You can configure the daemon service to monitor the running status of applications and restart applications immediately when they stop running.

The installation SuperVisor

sudo apt-get python-setuptools
easy_install supervisorCopy the code

Configure the SuperVisor

mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.confCopy the code

It’s going to change the supervisord.conf file and it’s going to add code at the end

[include]
files = conf.d/*.confCopy the code

Then reload the configuration file for it to take effect

supervisorctl reloadCopy the code


6. Configure the daemon of ASP.Net Core

Create a conf file such as DataMining. Conf in /etc/supervisor/conf.d and add the following contents to the file:

[program:DataMining]
command=sudo dotnet AngularDemo01.dll ; The directory = / usr/publish/DataMining/netcoreapp3.1 / publish /; autorestart=true ;
stderr_logfile=/var/log/DataMining.err.log ;
stdout_logfile=/var/log/DataMining.out.log ;
environment=ASPNETCORE_ENVIRONMENT=Production ;
user=root ; 
stopsignal=INTCopy the code

Save and exit, and then run the following code on the terminal

supervisord -c /etc/supervisor/supervisord.conf
ps -ef | grep DataMiningCopy the code

If the dotnet AngularDemo01.dll process is running successfully, you can access it from the browser.

Error handling Reference:

  • unix:///tmp/supervisor.sock no such file

  • unknown error making dispatchers for ‘xxx’: EACCES

  • Can’t drop privilege as nonroot user


7. Configure the Supervisor to start

In/usr/lib/systemd/new supervisord system directory service, service in the services file add the following code:

# dservice for systemd (Deepin)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=supervisord -c /etc/supervisor/supervisord.conf
ExecStop=supervisorctl shutdown
ExecReload=supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.targetCopy the code

It is then run the following command to set up the supervisord.service

systemctl enable supervisordCopy the code

Run the following command to verify whether it is running on the container

systemctl is-enabled supervisordCopy the code