. net core webapi (III) deployment on Linux server

Time:2020-3-22

Pigeon for a long time, finally have a time to continue to write, after the last one, and write (water) one, what are the shortcomings please point out, thank you.

There are two necessary software, putty and PSCP, which I have uploaded to the blog park. Please click here for download.

1、 Prepare server

First of all, as before, we went to Tencent cloud to complete a cloud server, and chose CentOS image.

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

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

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

Then we can install the. Net core running environment.

2、 Install. Net core environment

First go to. Net Microsoft official 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 one.

Find the corresponding version.

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

 

Let’s copy the first command first, and the execution will be finished soon.

Then we execute the second 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 was successful.

3、 Upload startup project

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

If you have a little partner who is not familiar with the operation command, you can set up a pagoda panel for operation. It’s more convenient to use graphics. In the third part of my previous server purchase + preliminary setup, I won’t go into details here. ~ omega =

Find the uploaded project file. The figure is easy. I put it directly in the root directory. Please don’t follow me. (~ ~)

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

Then execute the command dotnet firstapi.dll to find out whether it has been started successfully, which is the same as the first way in the previous article.

However, this can only be accessed locally on the server, and no effect can be seen on the server. Let’s end with Ctrl + C first.

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

  dotnet FirstApi.dll –server.urls “http://*:5555”

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

It’s over here, isn’t it a little short ( ̄ ェ), so 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 the 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

Unpack it.

  tar -xvf nginx-1.17.5.tar.gz

Then go to the unzipped directory. Execute sequentially

  ./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 directly access IP locally, you can see the welcome to nginx page.

5、 Configure nginx

Then we go to nginx configuration directory.

  cd /usr/local/nginx/conf

Create a Vhost folder. (the folder name is optional, but the path is 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 start 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 is saved and exited, enter the parent directory.

Edit the 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 to 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!!! ∑ (゚゚゚ノノノ), 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, it’s at least one essay a month (because I’m lazy). Last month, something broke down, and I have to continue to look for work QAQ, so the next one is.. Well, it depends on the situation

Recommended Today

Python basics Chinese series tutorial · translation completed

Original: Python basics Python tutorial Protocol: CC by-nc-sa 4.0 Welcome anyone to participate and improve: a person can go very fast, but a group of people can go further. Online reading Apache CN learning resources catalog introduce Seven reasons to learn Python Why Python is great Learn Python introduction Executing Python scripts variable character string […]