Deploying ASP. NET Core using Apache in a Linux environment

Source: Internet
Author: User
Tags dotnet

In the previous articles, we explored how to install the ASP. NET core runtime environment in a Linux environment and deploy the ASP. NET core project in Jexus, in this article we will explore how to deploy ASP. NET core in Apache (Apache).
We are fortunate to be able to learn and explore ASP.

This article runs the following environment:




(1) Installing the Apache Web server

Run the command line as follows:

sudo yum update-y//Update Warehouse

sudo yum-y install httpd mod_ssl//install Apache Web server

(2) Create an empty ASP. NET Core MVC Project

Run the command as follows:

Cd/home//Navigate to the home directory

dotnet New Mvc-o Hellomvc

Next we make some changes to the empty project to match the current operating environment

1?? Add a specified port for the Program.cs class Buildwebhost method to run





2?? Add the Microsoft.AspNetCore.HttpOverrides namespace in Startup.cs and add the URL middleware in the Configure method







Debug whether the current project is running properly

Run the command as follows:

CD/HOME/HELLOMVC//Navigate to the specified directory

Dotnet Run//running current project

Running successfully, the effect is as follows:





(3) Build the project deployment file

Run the command as follows:

Mkdir-p/VAR/ASPNETCORE/HELLOMVC//New Catalog Hellomvc

CD/HOME/HELLOMVC///Navigate to the specified directory

dotnet Publish-o/VAR/ASPNETCORE/HELLOMVC//Generate Deployment file

Because it is an empty project, we copy the View folder to the deployment directory

The directory structure is as follows:




Run the following command to test whether the published program is functioning properly.
Dotnet/var/aspnetcore/hellomvc/hellomvc.dll




(4) Modify Apache website configuration file

Run the following command

cd/etc/httpd/conf.d///Navigate to the specified directory

Touch hellomvc.conf//new file named hellomvc.conf

VI hellomvc.conf//Open hellomvc.conf


Well, that's it. You're not going to copy it. (I know the command line is very painful, so I have to install a graphical interface)




See if the configuration is working

sudo service httpd configtest




Re-launch Apache

sudo systemctl restart httpd

sudo systemctl enable httpd



OK, now Apache has forwarded the request at http://localhost:80 to H ttp://127.0.0.1:7000


(4) Setting Kestrel Guardian

With ASP. NET core running on Kestrel, we use systemd.Start and monitor Kestrel.

Create a service definition file

sudo nano/etc/systemd/system/kestrel-hellomvc.service

Note: If you are prompted Nano:command not found, the Nano may not be installed
Execute the Yum install Nano command, and then execute the Create service definition again after installing the Nano
File command.

The contents of the service definition file are as follows:







Save the file and enable the service, and then verify that it is running

Systemctl Enable Kestrel-hellomvc.service

Systemctl Start Kestrel-hellomvc.service

Systemctl Status Kestrel-hellomvc.service






OK, let's run the browser


Deploying ASP. NET Core using Apache in a Linux 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.