How to deploy. Net core webapi on Linux server

Time:2020-9-17

Pigeon for a long time, finally have a time to continue to write, followed by the last one, and wrote (water) an article, there are any shortcomings, please point out, thank you very much.

Here are two softwares that need to be used, putty and PSCP. I have uploaded them to the blog Garden. Please click here to download.

1、 Prepare server

First of all, as before, go to Tencent cloud to set up a cloud server and select the image of CentOS.

Then complete the purchase as before and get the IP address of the public network.

Then we copy the IP address of the public network. I used putty to log in remotely.

Enter the root user name and the password you set before to log in.

Then, we can install the running environment of. Net core.

2、 Net core installation environment

First go to the. Net Microsoft website to find the corresponding version.

  https://dotnet.microsoft.com/download

Choose Linux. This is version 3.0. Because I used version 2.2 before, I choose the last one to find my corresponding version. If it is version 3.0, just click the second.

Find the corresponding version.

Select CentOS 7 – x64 and two terminal commands appear. The first line of command is to add the package source, and the second line is to install the. Net core version of the package.

Let’s copy the first line of command and execute it quickly.

Then we execute the second line of command. The download is slow. Just wait patiently. If there is a prompt in the middle, enter y to confirm.

After the installation is complete, enter dotnet — info to verify that the installation is successful.

3、 Upload startup project

After the environment is installed, we need to copy the project files that have been sent to the server. I used the PSCP software to upload the files.

If you have a small partner who is not familiar with the operation command, you can build a pagoda panel for operation, which is more convenient in graphical way. There is one in the third part of my previous server purchase + preliminary construction, which will not be repeated here.  ̄ω ̄=

Find the uploaded project file, figure easy, I put it directly in the root directory, you don’t want to learn from me. ( ̄. ̄)

Then enter the project directory and check the files in it. Remember not to miss the previous XML file.

Then execute dotnet FirstApi.dll Command, you can find that it has been successfully started, is it the same as the first method in the previous article.

However, this can only be accessed locally on the server, and there is no effect on the server. Let’s finish with Ctrl + C.

Then we enter the following command to start it on port 5555.


dotnet FirstApi.dll --server.urls http://*:5555

  

Then we used the local browser to access the IP port and succeeded. ( ̄︶ ̄) A kind of

It’s over here, isn’t it a little short (~ ェ), so just use nginx by the way.

4、 Nginx installation

Nginx (engine x) is a high-performance HTTP and reverse proxy web server — from Baidu Encyclopedia

First of all, let’s go to nginx website to see what the latest version is.

  http://nginx.org/en/download.html

Then, execute the following command to download it.


wget http://nginx.org/download/nginx-1.17.5.tar.gz

Unzip it.


tar -xvf nginx-1.17.5.tar.gz

Then go to the unzipped directory. Carry out in turn


./configure
make
make install

Install.

After the installation, we go to the / usr / local directory to find the installed nginx directory. (the previous installation package can be deleted)

Then we execute the following command to start nginx.


/usr/local/nginx/sbin/nginx

If you visit IP directly locally, you can see the welcome to nginx page.

5、 Configure nginx

Next, we go to the nginx configuration directory.


cd /usr/local/nginx/conf

Create a Vhost folder. (the name of the folder is optional, but the path is also optional.)


mkdir vhost

Enter the folder.


cd vhost

Create a conf file.


vi firstapi.conf

The contents of the document are as follows. (since the default HTTP boot port of dotnet is 5000, I will use 5000)


server {
 listen 888;
 server_name localhost;
 root /root/FirstApi/;
 index index.html index.htm;

 location / {
 proxy_pass http://localhost:5000;
 }
}

ESC +: after WQ save and exit, enter the superior directory.

edit nginx.conf Configuration file.


vi nginx.conf

Add the directory address you just created to the last line of HTTP {}. (note in http {})


include /usr/local/nginx/conf/vhost/*.conf;

Then save and exit.

Execute the following two sentences to restart nginx.


/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx-s reload

Then the local browser accesses the configured port 888, 502 error! ∑ (゚゚゚ノノ), and forgot to start the project…

Enter the project directory.


cd /root/FirstApi

Direct start.


dotnet FirstApi.dll

Then visit again, OK.

Well, let’s get here for a while. According to the plan, I will write at least one essay a month (because I am lazy). Last month, something broke down. Moreover, I will continue to look for a job, QAQ, so the next article will be.. Well, it depends_ ー)ノ

This article introduces the method of. Net core webapi deployment on Linux server. For more information about. Net core webapi deployment to Linux, please search the previous articles of developeppaer or continue to browse the related articles below. I hope you can support developeppaer more in the future!

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]