Centos7+nginx deploying the ASP. NET Core MVC site

Source: Internet
Author: User
Tags dotnet

1. Install. NET Core

See the official website installation tutorial.

    1. Select the Linux distribution asCentos/Oracle
    2. Add Dotnet's Yum warehouse configuration

      $ sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
    3. Installing the. NET SDK

      #更新系统软件sudo yum update #安装dotnet sdksudo yum install dotnet-sdk-2.1
    4. Use dotnet --info the command to display information about. NET Core.

2. Installing Nginx

See the website installation configuration tutorial.

    1. Configure the Yum repository, create /etc/yum.repos.d/nginx.repo , and configure the following:
[nginx]name=nginx repo#baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/#OS为rhel或centos#OSRELEASE为centos版本,6或7baseurl=http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1
    1. Get the public key file
wget nginx.org/keys/nginx_signing.key
    1. Import Public key File
rpm --import nginx_signing.key
    1. Installing Nginx
sudo yum -y install nginx
3. Set Nginx to boot
    1. Create the Nginx.service file in the system service directory and set the file contents as follows:
#服务的说明[Unit]#描述服务Description=nginx#描述服务类别After=network.target#服务运行参数的设置  [Service]#Type=forking是后台运行的形式Type=forking#服务的具体运行命令ExecStart=/usr/local/nginx/sbin/nginx#重启命令ExecReload=/usr/local/nginx/sbin/nginx -s reload#停止命令ExecStop=/usr/local/nginx/sbin/nginx -s quit#PrivateTmp=True表示给服务分配独立的临时空间PrivateTmp=true #运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3  [Install]WantedBy=multi-user.target
    1. Set to boot
systemctl enable nginx.service
    1. Other administrative commands
#启动nginx服务systemctl start nginx.service #停止开机自启动systemctl disable nginx.service#查看服务当前状态systemctl status nginx.service#重新启动服务systemctl restart nginx.service #查看所有已启动的服务systemctl list-units --type=service
4. Configure Nginx
    1. Add nginx config file myapp.conf, and do the following configuration:
 Proxy_set_header Host $http _hostserver {#监听端口号 listen 8081;    #监听地址 server_name localhost 192.168.1.202;    #charset Koi8-r;        #access_log/var/log/nginx/host.access.log Main;        #设置代理 location/{#Kestrel上运行的asp. NET core MVC website address Proxy_pass http://localhost:8080;        Proxy_http_version 1.1;        Proxy_set_header Upgrade $http _upgrade;        Proxy_set_header Host $http _host;    Proxy_cache_bypass $http _upgrade;    } #error_page 404/404.html;    # REDIRECT Server error pages to the static page/50x.html # Error_page 502 503 504/50x.html;    Location =/50x.html {root/usr/share/nginx/html; } # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {# Proxy_pass/http/    127.0.0.1;           #} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {# root    html #   Fastcgi_pass 127.0.0.1:9000;    # Fastcgi_index index.php;    # Fastcgi_param Script_filename/scripts$fastcgi_script_name;    # include Fastcgi_params; #}
    1. Re-loading Nginx
nginx -s reload
5. Publishing Web sites, configuring services and firewalls
    1. Post a Web site and upload it to the server after publishing it.
    2. Use the dotnet myapp.dll startup Web site.
    3. Open the site's address in a browser and detect that the site is up and running.
    4. If you need extranet access, you need to open the appropriate port on the firewall. For specific operations see:
#添加80端口:firewall-cmd --zone=public --add-port=80/tcp --permanent#删除防火墙端口: firewall-cmd --zone=public --remove-port=12345/tcp --permanent#重新加载防火墙: firewall-cmd --reload#重启防火墙:systemctl stop firewalld  systemctl start firewalld
    1. Configure the published Web site as a service, see Nginx Configuration for boot-up. Specific as follows:
#新建配置文件touch /etc/systemd/system/myapp.service#编辑配置文件:[Unit]Description=myapp web[Service]WorkingDirectory=/home/myapp/webExecStart=/usr/bin/dotnet /home/myapp/web/WebPortals.dllRestart=alwaysRestartSec=10  # Restart service after 10 seconds if dotnet service crashesSyslogIdentifier=myappEnvironment=ASPNETCORE_ENVIRONMENT=ProductionEnvironment=DOTNET_PRINT_TELEMETRY_MESSAGE=false[Install]WantedBy=multi-user.target#服务开机启动systemctl enable myapp.service#启动服务systemctl start myapp.service#查看服务状态systemctl status myapp.service

Centos7+nginx deploying the ASP. NET Core MVC site

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.