Nginx
主要配置内容
server {
listen 8070;
listen [::]:8070;
server_name _;
location / {
root /usr/share/nginx/html;
}
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
# 第一种代理前端的方式
location /substation {
alias /opt/static/substation;
index index.html index.htm;
}
# 第二种
location /watcon {
root /opt/static;
try_files $uri $uri/ /watcon/index.html;
index index.html index.htm;
}
# 代理后端
location /api/watcon {
proxy_pass http://121.36.151.190:8071/api/watcon;
}
}
对应的目录结构:
/opt/static/substation/index.html
/opt/static/watcon/index.html
踩坑
修改配置文件后无论怎么改都不生效. 后来发现好像是之前的nginx进程没有停掉, 一直在访问之前启动的nginx. 我也不明白为什么nginx到底怎么回事, 总之就是nginx -s reload实际是执行了的(因为故意改错的话会reload失败), 但不生效.
解决方案就是彻底停掉nginx, 然后启动.(如何停掉在下面操作手册)
操作手册
yum install -y nginx
systemctl start nginx
nginx -s reload
注意!!! 不要使用systemctl restart nginx, 因为nginx进程无法"优雅的"停止.
如果真的需要重启nginx, 可以:
netstat | grep 80(端口号)
从容停止Nginx:
https://blog.csdn.net/shenshulong/article/details/88767328
$ kill -QUIT 主进程号
例如:kill -QUIT 16391
这种方式相对来说会有一个停止的过程,先将子进程停止掉,然后再停掉主进程。
快速停止Nginx:
$ kill -TERM 主进程号
这种会比上面那种方法速度快些。
强制停止Nginx:
$ kill -9 主进程号
这种方式是最后的方法,强制停止。
版权声明:本文为qq_35772435原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。