Asp.Net Core2.0 released under linux

You can refer to: https://segmentfault.com/a/1190000012428781

You can also see the official Microsoft documentation.

The general steps are as follows:

1. Install .netcore under linux, run dotnet --versionthe command to check whether the installation is successful.

2. Create a new template website:

sudo vim /etc/systemd/system/kestrel-firstapp.service  

Create a new kestrel-firstapp.service file in the /etc/systemd/system directory, and then write a script as follows:

[Unit]
Description=Example .NET Web API App running on Ubuntu

[Service]
WorkingDirectory=/home/birdhumen/www/firstapp
ExecStart=/usr/bin/dotnet   /home/birdhumen/www/firstapp/test.dll
Restart=always
RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=dotnet-example
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target


The red mark is very critical, because I am operating under root, so it is directly the absolute path in the home directory /home/birdhumen/www/firstapp,

birdhumen is a common user name, www and firstapp are both created folders, firstapp distributes the dll of the published asp.net core2.0 template, and there are 7 or 8 files.

3. Then execute:

sudo systemctl enable kestrel-mysite.service # register service
sudo systemctl start kestrel-mysite.service # start service

sudo systemctl status kestrel-mysite.service # Check the running status of the service. If this sentence is wrong, there is a high probability that there is a problem with the script.

After success, you can see something like

localhost:5000

something, and then it means that the service has been successfully started. Directly under linux

wget http://localhost:5000

4. But it is still not accessible on the external network. You need to use nginx to see another article: https://blog.csdn.net/wcc27857285/article/details/80033364Install nginx


5. After installing nginx, you need to modify the nginx configuration file

Find the nginx directory, if you can't find it, use the command: whereis nginx

Currently under the ~/usr/local/nginx/conf/ directory, there are two files, nginx.conf and nginx.conf.default, the default one is the default, but nginx.conf is actually loaded.

vim nginx.conf

Find the server node and replace the text below the location with the following red text :

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;
    }
}

7.重启下服务:./nginx -s reload,  成功后,即可在外网访问linux的IP,即可访问到ASP.netcore2.0的模板网站了!



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324607976&siteId=291194637