ASP. NET Core program published to Linux production environment

Source: Internet
Author: User
Tags dotnet dedicated server
This article is mainly for everyone to introduce the ASP. NET Core program published to the Linux production environment, with a certain reference value, interested in small partners can refer to.

In this article we will show you how to deploy an ASP. NET core application on Ubuntu 14.04 server. We will place the ASP. NET core application behind a reverse proxy server, and the proxy server forwards the request to our Kestrel server. In addition, we will ensure that our web application is launched as a daemon. We need to configure a process management tool to help us recover programs in case of a program crash to ensure high availability.

Chapter:

    • Get ready

    • Copy your application

    • Configuring a reverse proxy server

    • Monitor our applications

    • Launch our App

    • Observation log

    • Make our applications Secure

Preparatory work

1. Access Ubuntu 14.04 Server using a standard account with sudo privileges;

2. ASP. NET core application.

Copy your application

Run dotnet publish to package your ASP. NET core application into a self-contained (self-contained) directory (publish directory where the program will be uploaded to the server and run). What is a self-contained (self-contained) program, please refer to my article:

. NET Core App types (portable apps & self-contained apps). Before the operation, the programs under the Publish directory are uploaded to the server-specified directory via the FTP tool (WINSCP, etc.). Next we run our program, specifically how to run the program please refer to this article: using. NET Core 1.0 To create a self-contained console app.

Configuring a reverse proxy server

A reverse proxy is a very common setting for dynamic Web applications. The reverse proxy terminates the current request and forwards the request to the back-end ASP.

Why to use a reverse proxy server

Kestrel, as a Web server, is excellent at handling dynamic content, but it is not as complete as those of a mature Web server, including IIS, Apache or Nginx. The reverse proxy server can offload some of the work from the HTTP server, including: Static content processing, caching, compression, and SSL. The reverse proxy server can be deployed on a dedicated server or in the same cluster as the HTTP server. In this example we will use Nginx as a reverse proxy server and deploy it on the same machine as the HTTP server.

Installing a proxy server

sudo apt-get install Nginx

Installing Nginx

sudo service nginx start

Start Nginx

Configure Nginx

Edit file:/etc/nginx/sites-available/default as follows:


server {Listen; 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; }}

Listen for the default port on port 80, HTTP, HTTP 1.1 for proxy, and transfer the original request to:http://localhost:5000.

After the above configuration is complete, use the following command to verify that the configuration file syntax is correct:

sudo nginx-t

If there is no problem with the configuration syntax, restart Nginx for the configuration to take effect:

sudo nginx-s reload

Monitor our web applications

Nginx will forward the request to your Kestrel server, but Kestrel is not like IIS on Windows, it does not manage your Kestrel process and in this article we will use Supervisor to launch our application, Self-recovery when the system starts or when a process crashes.

Install Supervisor:

sudo apt-get install Supervisor

Configuration Supervisor:

/etc/supervisor/conf.d/hellomvc.conf (a new file)


[Program:hellomvc]command=/usr/bin/dotnet/var/aspnetcore/hellomvc/hellomvc.dlldirectory=/var/aspnetcore/ hellomvc/autostart=trueautorestart=truestderr_logfile=/var/log/hellomvc.err.logstdout_logfile=/var/log/ Hellomvc.out.logenvironment=aspnetcoreenvironment=productionuser=www-datastopsignal=int

Restart Supervisord


sudo service Supervisor Stopsudo Service supervisor Start

Launch our web application

In this case, because we use Supervisor to manage our application, the application will be automatically opened by supervisor. When the operating system starts, Supervisor uses a System V initialization script as the daemon to start, and supervisor launches your application shortly after startup.

Observation log

Supervisord Log

sudo tail-f/var/log/supervisor/supervisord.log

Logs that we apply ourselves

Tail-f/var/log/hellomvc.out.log

Original translation: Publish to a Linux Production environment
Author: Sourabh Shirhatti

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.