systemctl restart nginx.service #重新启动服务
systemctl list-units –type=service #查看所有已启动的服务
4.防火墙配置(如果系统有防火墙就需要进行写入规则)
命令:firewall-cmd –zone=public –add-port=80/tcp –permanent(开放80端口)
命令:systemctl restart firewalld(重启防火墙以使配置即时生效)
5.配置nginx对ASP.NET Core应用的转发
修改 /etc/nginx/conf.d/default.conf 文件。
将文件内容替换为
| server { listen 80; location / { proxy_pass http://localhost:88; 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; } } |
重新加载nignx
| [root@localhost nginx]# nginx -s reload |
nginx的配置己完成
6.开启dotnet run进行测试
| [root@localhost ~]# cd /home/WebApplication1/ [root@localhost WebApplication1]# dotnet run Using launch settings from /home/WebApplication1/Properties/launchSettings.json... Hosting environment: Development Content root path: /home/WebApplication1 Now listening on: http://[::]:88 Application started. Press Ctrl+C to shut down. |
通过IP 80端口访问

六、配置守护服务(Supervisor)
目前存在三个问题
问题1:ASP.NET Core应用程序运行在shell之中,如果关闭shell则会发现ASP.NET Core应用被关闭,从而导致应用无法访问,这种情况当然是我们不想遇到的,而且生产环境对这种情况是零容忍的。
问题2:如果ASP.NET Core进程意外终止那么需要人为连进shell进行再次启动,往往这种操作都不够及时。
问题3:如果服务器宕机或需要重启我们则还是需要连入shell进行启动。
为了解决这个问题,我们需要有一个程序来监听ASP.NET Core 应用程序的状况。在应用程序停止运行的时候立即重新启动。这边我们用到了Supervisor这个工具,Supervisor使用Python开发的。
1.安装Supervisor
| [root@localhost /]# yum install python-setuptools -y [root@localhost /]#easy_install supervisor |
2.配置Supervisor
| [root@localhost /]#mkdir /etc/supervisor [root@localhost /]#echo_supervisord_conf > /etc/supervisor/supervisord.conf |
修改supervisord.conf文件,将文件尾部的配置
| [root@localhost /]# vi /etc/supervisor/supervisord.conf |
将里面的最后两行:
| ;[include] ;files = relative/directory/*.ini |
改为








