Linux+nginx+asp.net Core

Source: Internet
Author: User

Linux+nginx+asp.net Core

The "Getting Started with Docker basics and Examples" article describes the Docker deployment and the packaging examples of the associated. NET core. In this article I will take the Oss.offical.site site as an example, the main introduction under the Linux machine complete deployment process,. NET core in the Docker container run has been introduced here, the. NET core runtime environment I will introduce directly in Linux running scenes, The main content consists of the following parts:

1. Basic tools and Linux environment preparation

2.. Net core Environment installation and port configuration

3. Installation configuration of Nginx

4. Supervisor Daemon Installation Configuration

I. Infrastructure tools and LINUX environment preparation

Tool Description:

Ubuntu:azure Cloud Linux Host

Xshell: Free Linux Client Tools

FileZilla: Free File Upload (SFTP, FTP) tool

VS2017: Development Tools

This deployment is primarily through the Nginx load Agent. NET Core Service, which provides external site access. The host of the. NET core itself runs through its own Kestrel service. If you are a cloud host, remember to add 80 access ports in the admin console.

Then here I first create a WWW folder, as the root directory behind the site file, and set the relevant permissions, there may be a small need to pay attention to the problem, now many cloud host directly log on after the permissions are very low, need to use: Sudo-s command elevation permissions, Otherwise, creating the folder will cause insufficient permissions errors.

1. mkdir/home/www/ossoffical//Create Ossoffical site folder

2. Chown [-r] Account name ossoffical//Add the account name to the owner of the WWW folder, ensure the subsequent SFTP upload folder, etc. can also be operated without the right to mention

 Two.. Net core Environment installation and port configuration

1. Install, here refer to the Microsoft Official website, I use the Ubuntu 14.04 version, the main implementation of the following several 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-related settings

Note here that the. NET core project created by the current version will use port 5000 by default without having to specify a specific port. But this will be removed in subsequent releases, see Official documentation:

And I also want to specify a specific port, so that after more sites to prevent conflicts, I modify my project in the program file content, specify 8000 port,

Note the order in which the current project is published if debugging cannot be opened in vs.

3. Upload project file to run

A. Uploading the project file to the Ossoffical directory via FileZilla

B. Via the command client into the ossoffical directory (cd/home/www/ossoffical), execute: dotnet OSS. Offical.Site.dll (my current site project assembly name), results:

Exit Execution Ctrl + C. Of course we can also execute "dotnet OSS." Offical.Site.dll & ", let it run in the background, just this more convenient for us to view. You can access the corresponding 8000 ports at this time (please note the open access port for cloud hosts).

Three. Nginx Installation

1. Execute: sudo apt-get install nginx command

2. After the installation is complete, access the corresponding 80 ports as follows:

3. Configure the Agent

A. mkdir/etc/nginx/hosts create a folder to place the site configuration file

B. Execute cd/etc/nginx/hosts into the directory, execute: VI ossoffical Press "I" to add the following:


server {
Listen 80;

Index index.html index.htm;

server_name www.osscoder.com; #域名

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 save.

4. Modify Nginx configuration file, vi/etc/nginx/nginx.conf

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

5. Restart Nginx server: sudo service nginx restart (reload)

6. Enter the site directory, dotnet OSS. Offical.Site.dll &, make sure the site runs correctly and access www.osscoder.com as follows:

Four. Daemon installation configuration

To ensure a stable operation of the service, we install the daemon to ensure that the application will restart normally if an unexpected interruption occurs.

1. Install, execute: sudo apt-get install supervisor

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

[Program:oss. Offical.site]
Command=dotnet OSS. Offical.Site.dll//commands to execute
directory=/home/www/ossoffical//Command Execution directory
Environment=aspnetcore__environment=production #环境变量
User=osscoder//user identity for Process execution
Stopsignal=int
Autostart=true
Autorestart=true
startsecs=3//Auto restart interval
Stderr_logfile=/var/log/ossoffical.err.log//Standard error log
Stdout_logfile=/var/log/ossoffical.out.log//Standard output log

Replace the corresponding directory and name, please delete the comment, or sometimes the command execution failure. Restart Supervisor after completion:

sudo service supervisor Stop

 sudo service supervisor Start

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

Linux+nginx+asp.net Core

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.