1. Install. NET Core
See the official website installation tutorial.
- Select the Linux distribution as
Centos/Oracle
Add Dotnet's Yum warehouse configuration
$ sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
Installing the. NET SDK
#更新系统软件sudo yum update #安装dotnet sdksudo yum install dotnet-sdk-2.1
Use dotnet --info
the command to display information about. NET Core.
2. Installing Nginx
See the website installation configuration tutorial.
- 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
- Get the public key file
wget nginx.org/keys/nginx_signing.key
- Import Public key File
rpm --import nginx_signing.key
- Installing Nginx
sudo yum -y install nginx
3. Set Nginx to boot
- 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
- Set to boot
systemctl enable nginx.service
- 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
- 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; #}
- Re-loading Nginx
nginx -s reload
5. Publishing Web sites, configuring services and firewalls
- Post a Web site and upload it to the server after publishing it.
- Use the
dotnet myapp.dll
startup Web site.
- Open the site's address in a browser and detect that the site is up and running.
- 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
- 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