"ASP. Publish to a linux-ubuntu 14.04 Server Production Environment

Source: Internet
Author: User
Tags dotnet

Submary

Upgraded again, the directory structure has changed.

Project.json and Visual Studio with. NET Core

On March 7, the. NET core and ASP. Documentation is updated for the release of Visual Studio 2017. The previous version of the documentation used Visual Studio and pre-release tooling based on the project.json file.

Mapping between Project.json and Csproj properties 2017-3-134 min To read duration author
    • Author Nate McMaster

A significant design change was implemented during the development of the. NET Core tool, which is to transfer. NET core projects to the Msbuild/csproj format instead of supporting Project.json files

Official documents from Microsoft: https://docs.microsoft.com/zh-cn/dotnet/core/tools/project-json-to-csproj

It doesn't seem to be true ...

This one Project.json is for the previous 1.0 version. To 1.1 disappeared ...... NET Core Program Deprecation Project.json

Microsoft eventually announced that the Project.json experiment would fail and would revert to using the. csproj file. But the shift will not happen immediately, and the recently released. NET Core RC2 (also known as Tooling Preview 1) will continue to use. Xproj and Project.json.

Starting with. NET Core rtm/tooling Preview 2, Visual Studio will automatically rename the. xproj file to. csproj. But Project.json's features are not changing yet.

After preview 2, Microsoft will continue to move the Project.json functionality to. csproj. You only need to upgrade Visual Studio to complete some updates. For example, although Visual Studio insists on one add source file,. csproj now supports wildcard characters. Other functions of Project.json integration into the. csproj may require more work to be done.

After the migration is complete, project.json may exist only as an alternative to the NuGet package, at which time Project.json will be renamed to Nuget.json.

Msbuild

You may not know that the. csproj file is really just a professional version of the. MSBuild script. This means that when. NET core is running, MSBuild must be available.

For a long time, Microsoft has been looking for ways to add nuget functionality directly to MSBuild. (MSBuild now relies on extended access to NuGet.) )

asp.netcore1.1 version removed the Project.json after how to package the build cross-platform package, in order to better follow up the development of Aspnetcore, before used to do Netcore development vs2015 Uninstall and install vs2017, This brings me the direct benefit is that I reported the red of the C plate to make up about 10GB of space, from here directly can feel the vs2017 volume so small; previously wrote an open source Netcore service article Open Source A service plug-in that runs across platforms-Taskcore.mainform, which tells the Netcore project to build and deploy in Win7 and ubuntu16.04Examples of the system, interested friends can go to see, the following start the content of this article, I hope you can like, but also hope that you more " Scan Code Supportand RecommendedThank

Publish to a Linux Production environment

by Sourabh Shirhatti

In the This guide, we'll cover setting up a Production-ready ASP. Environment on an Ubuntu 14.04 Server.

We'll take an existing ASP. NET Core application and place it behind a reverse-proxy server. We'll then setup the Reverse-proxy server to forward requests to our Kestrel Web server.

Additionally we'll ensure our web application runs on startup as a daemon and configure a Process management tool to Hel P Restart our web application in the event of a crash to guarantee high availability.

Prerequisites
    1. Access to an Ubuntu 14.04 Server with a, user account with sudo privilege.

    2. An existing ASP. NET Core application.

Copy over your app

Run from dotnet publish your dev environment to package your application into a self-contained directory the can run on your serve R.

Before we proceed, copy your ASP. NET Core application to your server using whatever tool (SCP, FTP, etc) integrates into Y Our workflow. Try and run the app and navigate to http://<serveraddress>:<port> your browser to see if the application runs fine on Linux. I recommend you have a working app before proceeding.

[! NOTE] You can use the Yeoman to create a new ASP. NET Core application for a new project.

Configure a reverse proxy server

A reverse proxy is a common setup for serving dynamic Web applications. The reverse proxy terminates the HTTP request and forwards it to the ASP.

Why use a reverse-proxy server?

Kestrel is great for serving dynamic content from ASP. However the Web serving parts aren ' t as feature rich as Full-fe atured servers like IIS, Apache or Nginx. A reverse Proxy-server can allow the offload work like serving static content, caching requests, compressing requests, and SSL termination from the HTTP server. The reverse proxy server may reside to a dedicated machine or May is deployed alongside an HTTP server.

For the purposes of this guide, we is going to use a single instance of Nginx that runs on the same server alongside your HTTP server. However, based on your requirements your may choose a different setup.

Install Nginx
sudo apt-get install Nginx

[! NOTE] If you plan to install the optional Nginx modules, you are required to the build Nginx from source.

We are going to apt-get install Nginx. The installer also creates a system V init script, runs Nginx as daemon on System startup. Since We just installed Nginx for the first time, we can explicitly start it by running

sudo service nginx start

At the should is able to navigate to your browser and see the default landing page for Nginx.

Configure Nginx

We'll now configure Nginx as a reverse proxy to forward requests to our ASP.

We'll be modifying /etc/nginx/sites-available/default the, so open it up in your favorite text editor and replace the contents with the following.

server {a    ;    /{        $http _upgrade;}}  

This is one of the simplest configuration files for Nginx, forwards incoming public traffic on your port to 80 a P ORT that 5000 your Web application would listen on.

Once you has completed making changes to your nginx configuration you can run to sudo nginx -t verify the syntax of your Configur ation files. If The configuration file test is successful you can ask for Nginx to pick up the changes by running sudo nginx -s reload .

Monitoring our WEB application

Nginx would forward requests to your Kestrel server, however unlike IIS on Windows, it does not mangage your Kestrel proces S. In this tutorial, we'll use supervisor to start our application on system boot and restart our process in the event O f a failure.

Installing Supervisor
sudo apt-get install Supervisor

[! NOTE] is supervisor a Python based tool and you can acquire it through PIP or Easy_install instead.

Configuring supervisor

Supervisor works by creating-processes based on data in its configuration file. When a child process dies, supervisor is notified via the SIGCHILD signal and supervisor can react accordingly and restart Yo ur Web application.

To has supervisor monitor our application, we'll add a file to the /etc/supervisor/conf.d/ directory.

/etc/supervisor/conf.d/hellomvc.conf

[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=home=/var/www/,aspnetcore_environment=productionuser=www-data stopsignal=intstopasgroup=truekillasgroup=true           

Once you do editing the configuration file, restart the process to change the supervisord set of programs controlled by S Upervisord.

sudo service Supervisor Stopsudo Service supervisor Start
Start our web application on startup

In our case, since we is using supervisor to manage our application, the application would be automatically started by sup Ervisor. Supervisor uses a system V Init script to run as a daemon on System boot and would susbsequently launch your application. If you chose does not have supervisor or an equivalent tool, you'll need to write a systemd or upstart or SysVinit script to start Your application on startup.

viewing logs

Supervisord logs messages about its own health and its subprocess ' state changes to the activity log. The path to the activity log was configured via the logfile parameter in the configuration file.

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

You can redirect application logs (and) in the program section of the STDOUT STERR your configuration file.

Tail-f/var/log/hellomvc.out.log
Securing Our Applicationenable AppArmor

Linux Security Modules (LSM) is a framework, which is part of the Linux kernel since Linux 2.6 that supports different imple Mentations of security modules. Is AppArmor a LSM this implements a Mandatory Access Control system which allows you to confine the program to a limited set of resources. Ensure AppArmor is enabled and properly configured.

Configuring our Firewall

Close off all external ports. Uncomplicated Firewall (UFW) provides a frontend for by iptables providing a command-line interface for configuring the Firew All. Verify that's configured to allow traffic on any ufw ports you need.

Enablesudo UFW allow 80/tcpsudo UFW allow 443/tcp
Securing Nginx

The default distribution of Nginx doesn ' t enable SSL. To enable all the security features we require, we'll build from source.

Download the source and install the build dependencies
# Install the build dependenciessudo apt-get updatesudo apt-get Install build-essential zlib1g-dev libpcre3-dev Libssl-dev Libxslt1-dev libxml2-dev libgd2-xpm-dev libgeoip-dev libgoogle-perftools-dev libperl-dev# Download Nginx 1.10.0 or Latestwget http://www.nginx.org/download/nginx-1.10.0.tar.gztar zxf nginx-1.10.0.tar.gz
Change the Nginx response name

Edit src/http/ngx_http_header_filter_module.c

"Server:your Web Server" CRLF;" Server:your Web Server"CRLF;  
Configure the options and build

The PCRE library is a required for regular expressions. Regular expressions is used in the location directive for the Ngx_http_rewrite_module. The Http_ssl_module adds HTTPS protocol support.

Consider using a Web application firewall like modsecurity to harden your application.

./configure--with-pcre=. /pcre-8.38--with-zlib=. /zlib-1.2.8--with-http_ssl_module--with-stream--with-mail=dynamic
Configure SSL
    • Configure your server to listen to HTTPS traffic on port by 443 specifying a valid certificate issued by a trusted Certi Ficate Authority (CA).

    • Harden your security by employing some of the practices suggested below like choosing a stronger cipher and redirecting AL L traffic over HTTP to HTTPS.

    • Adding an HTTP Strict-Transport-Security (HSTS) header ensures all subsequent requests made by the client is over HTTPS only.

    • Do not add the strict-transport-security header or chose a appropriate max-age if you plan to disable SSL on the future.

ADD /etc/nginx/proxy.conf configuration file.

[!code-nginxmain]

Edit the /etc/nginx/nginx.conf configuration file. The example contains both HTTP and server sections in one configuration file.

[!code-nginxmain]

"ASP. Publish to a linux-ubuntu 14.04 Server Production Environment

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.