Linux + Nginx + Asp.net Core and daemon deployment, nginxcore

Source: Internet
Author: User
Tags filezilla nginx server

Linux + Nginx + Asp.net Core and daemon deployment, nginxcore

The previous article Docker basics and examples describes Docker deployment and related. net core packaging examples. In this article, I will use oss. offical. the site is used as an example to describe the complete deployment process on linux machines ,. net core running in docker containers has been introduced, here.. net core running environment I will introduce the scenarios that run directly in linux. The content mainly includes the following parts:

1. Basic tools and Linux environment preparation

2. Install the. Net Core environment and configure the port

3. install and configure Nginx

4. install and configure the Supervisor daemon

I. Basic tools and Linux environment preparation

Tool introduction:

Ubuntu: azure cloud linux host

Xshell: Free linux client Tool

FileZilla: a free File Upload (sftp, ftp) Tool

Vs2017: development tools

 

This deployment mainly uses the Nginx load proxy. net core service to provide external site access .. The host of net core itself runs through its own Kestrel service. If you are a VM instance, remember to add Port 80 on the console.

Here, I will first create a www folder, which serves as the root directory for storing site files at the back end, and set relevant permissions. There may be a small issue to be noted here, currently, the permission is very low after you log on to a multi-cloud host directly. You need to use the: sudo-s command to raise the permission. Otherwise, the folder will be created with insufficient permissions.

1. mkdir/home/www/ossoffical // create an ossoffical site folder

2. chown [-R] account name ossoffical // Add the account name to the owner of the www folder to ensure that subsequent sftp upload folders can also be operated without permission escalation.

 

 Ii. Installation of. Net Core environment and port configuration

1. for installation, refer to the official website of Microsoft. I am using Ubuntu 14.04 and mainly execute the following commands:

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893

sudo apt-get update

sudo apt-get install dotnet-dev-1.0.1

2. vs port settings

Note that the. net core project created in the current version uses port 5000 by default without specifying specific ports. However, this will be removed in later versions. For details, see the official documentation:

In addition, I also want to specify a specific port so as to prevent conflicts when the site is too large. I modify the content of the Program file in my project and specify port 8000,

Pay attention to the order. Otherwise, debugging may fail to be enabled in vs to release the current project.

3. Upload the project file to run

A. Upload the project file to the ossoffical directory through filezilla

B. Run the command client to enter the ossoffical directory (cd/home/www/ossoffical) and run dotnet OSS. Offical. Site. dll (my current Site project assembly name). The result is:

 

Exit and execute ctrl + c. Of course, we can also execute "dotnet OSS. Offical. Site. dll &" to run it in the background, but this is more convenient for us to view. In this case, you can access the corresponding port 8000 (the VM instance must open the access port ).

 

Iii. Nginx Installation

1. Run the sudo apt-get install nginx command.

2. After the installation is complete, access the corresponding port 80, which should be as follows:

3. Configure proxy

A. mkdir/etc/nginx/hosts create a folder for storing the site configuration file

B. Run cd/etc/nginx/hosts to enter the directory. Run vi ossoffical and press "I" to add the following content:


Server {
Listen 80;

Index index.html index.htm;

Server_name www.osscoder.com; # Domain Name

Location /{
Proxy_pass http: // 127.0.0.1: 8000; # The address port just set
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;
}
}

Exit and save.

4. Modify the nginx configuration file vi/etc/nginx. conf.

At the end of the http node, add: include/etc/nginx/hosts /*;

5. restart the nginx server: sudo service nginx restart (reload)

6. Go to the Site directory, dotnet OSS. Offical. Site. dll &, and ensure that the Site runs correctly. Visit www.osscoder.com, as shown below:

 

4. Daemon installation and configuration

To ensure stable service running, we install the daemon to ensure normal restart in case of abnormal interruptions to the application.

1. install and run sudo apt-get install supervisor.

2. After the installation is successful, enter the/ect/supervisor/conf. d/directory, add the ossoffical. conf file, and add the following content:

[Program: OSS. Offical. Site]
Command = dotnet OSS. Offical. Site. dll // command to be executed
Directory =/home/www/ossoffical // directory for Command Execution
Environment = aspnetcoreappsenvironment = Production # environment variable
User = osscoder // user identity for Process Execution
Stopsignal = INT
Autostart = true
Autorestart = true
Startsecs = 3 // Automatic Restart Interval
Stderr_logfile =/var/log/ossoffical. err. log // Standard Error log
Stdout_logfile =/var/log/ossoffical. out. log // standard output log

Change the corresponding directory and name. Delete the comment. Otherwise, the command execution may fail. Restart supervisor after completion:

Sudo service supervisor stop

 Sudo service supervisor start

After completion, you can kill the process or restart the machine for testing.

 

I have recently developed an OSS open source project. Now I have an OSS instance. common, OSS. http, OSS. social and OSS. if you are interested in several projects in PayCenter, please contact me or follow the public account OSSCoder

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.