ASP. NET core running configuration in CENTOS7 environment

Source: Internet
Author: User
Tags dotnet

Environment Description:

Server System: CentOS 7.2.1511

Related tools: Xshel,xftp

Server Software Software:. Netcore,nginx,supervisor

Ready to publish the program

installing the. NET Core SDK for CentOS7

Open URL: Https://www.microsoft.com/net/core#linuxcentos

Copy the following command, stepping:

sudo yum install libunwind libicu curl-ssl-o dotnet.tar.gz https://go.microsoft.com/fwlink/?  linkid=835019 sudo mkdir-p/opt/dotnet && sudo tar zxf dotnet.tar.gz-c/opt/dotnet sudo ln-s/opt/dotnet/dotnet /usr/local/bin

Enter dotnet –info to see if the installation was successful

Configuration Nginx

Download Installation Nginx, step to execute the following command:

Curl-o nginx.rpmhttp://nginx.org/packages/centos/7/noarch/rpms/nginx-release-centos-7-0.el7.ngx.noarch.rpm RPM- IVH nginx.rpm Yum install nginx systemctl start Nginx to start Nginx Systemctl enable Nginx to set the boot (Linux downtime, restart will automatically run Nginx does not need To connect to the input command).

Configuring firewalls

Command: Firewall-cmd--zone=public--add-port=80/tcp--permanent (open 80 port) command: Systemctl restart FIREWALLD (Restart the firewall for immediate configuration) Test if Nginx can be accessed.

Configuring nginx forwarding for asp . Net Core applications

Modify The/etc/nginx/conf.d/default.conf file to replace the contents of the file with:

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

Upload to CentOS for coverage.

execution:nginx –s Reload make it effective immediately

Run ASP. NET Core application, retry access. If access is not caused by the SELinux protection mechanism, we need to add nginx to selinux White list, we solve this problem by some orders.

Yum install Policycoreutils-python sudo cat/var/log/audit/audit.log | grep Nginx | grep denied | Audit2allow-m Mynginx sudo semodule-i mynginx.pp

Re-visit should be no problem.

Configure the Daemon service ( Supervisor)

installation Supervisor

Yum Install Python-setuptools Easy_install Supervisor


Configuration Supervisor

Mkdir/etc/supervisor echo_supervisord_conf >/etc/supervisor/supervisord.conf Modify the supervisord.conf file to configure the tail of the file as: [ Include]files = Conf.d/*.ini or [include]files = conf.d/*.conf

Configure the for the protection of the ASP. NET Core app, create the following INI file:

[Program:aspnetcorewebapi]command=dotnet aspnetcorewebapi.dlldirectory=/root/wwwroot/autostart=trueautorestart= truestderr_logfile=/var/log/aspnetcorewebapi.err.logstdout_logfile=/var/log/ Aspnetcorewebapi.out.logenvironment=aspnetcore_environment=productionuser=rootstartsecs=1stopsignal=int

Copy the file to:"/etc/supervisor/conf.d/

run Supervisordto see if the command is valid, as follows:

Supervisord-c/etc/supervisor/supervisord.conf

Ps-ef | grep Aspnetcorewebapi

If the service is started, modify the configuration file to use the "supervisorctl reload" command to make it effective.

Configuration Supervisor Boot up

Create a new "Supervisord.service" file

# Dservice for Systemd (CentOS 7.0+) # by Et-cs (Https://github.com/ET-CS) [Unit]description=supervisor daemon [Service] Type=forkingexecstart=/usr/bin/supervisord-c/etc/supervisor/supervisord.confexecstop=/usr/bin/supervisorctl Shutdownexecreload=/usr/bin/supervisorctl reloadkillmode=processrestart=on-failurerestartsec=42s [Install] Wantedby=multi-user.target

Copy the file to:"/usr/lib/systemd/system/supervisord.service"

Execute command:systemctl enable Supervisord

Execute command:systemctl is-enabled Supervisord # to verify the boot start

using supervisorctl

Supervisorctl is a command-line client tool for Supervisord, which needs to be specified with supervisord to use the same configuration file when booting, or Supervisord to find the configuration file in the same order.

Supervisorctl-c/etc/supervisord.conf

the above command will go into the supervisorctl Shell interface, and then you can execute different commands:

> Status # View program status > Stop usercenter # Close Usercenter program > Start usercenter # start Usercenter program > Restart user Center # Restart Usercenter Program > Reread # Read configuration file with update (add), do not start newly added program > update # Restart Profile Modified Program > Status # View program status


ASP. NET core running configuration in CENTOS7 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.