原文地址:http://www.cnblogs.com/ants/p/5732337.html#_label5
参考地址:http://www.cnblogs.com/hustskyking/p/nginx-configuration-start.html
相关命令:
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确
关闭nginx:
nginx -s stop :快速停止nginx
quit :完整有序的停止nginx
其他的停止nginx 方式:
ps -ef | grep nginx
kill -QUIT 主进程号 :从容停止Nginx
kill -TERM 主进程号 :快速停止Nginx
pkill -9 nginx :强制停止Nginx
nginx -c /path/to/nginx.conf
平滑重启nginx:
kill -HUP 主进程号
安装Nginx
curl -o nginx.rpm http://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 来启动nginx。
输入:systemctl enable nginx 来设置nginx的开机启动(linux宕机、重启会自动运行nginx不需要连上去输入命令)
配置防火墙
命令:firewall-cmd --zone=public --add-port=80/tcp --permanent(开放80端口)
命令:systemctl restart firewalld(重启防火墙以使配置即时生效)
测试nginx是否可以访问。
配置nginx对ASP.NET Core应用的转发
修改 /etc/nginx/conf.d/default.conf 文件。
在文件中加入或修改:
server {
listen ;
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;
}
}
执行: nginx -s reload 使其即时生效
运行ASP.NET Core应用程序
这时候再次尝试访问。
这个问题是由于SELinux保护机制所导致,我们需要将nginx添加至SELinux的白名单。
接下来我们通过一些命令解决这个问题。
yum install policycoreutils-python sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx sudo semodule -i mynginx.pp
ps:SELinux保护机制详细介绍文章:https://www.linuxidc.com/Linux/2018-08/153625.htm
再次访问