CentOS7部署supervisor和nginx

安装NGINX

跟python的编译安装一摸一样

1
2
3
4
5
tar -xf nginx-1.13.9.tar.gz
cd nginx-1.13.9/
./configure --prefix=/usr/nginx
make
make install

修改配置文件

禁止后台启动,否则supervisor无法监控,出现nginx不停重启的问题

1
daemon off;

编写配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
location / {
root /home/html;
index index.html index.htm;
}
location /kl {
root /home/html; #静态资源在这里,因此static都要放在这里;
proxy_pass http://127.0.0.1:9999/kl;
proxy_redirect default;
proxy_set_header Cookie $http_cookie;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
index index.html index.htm;
}
location /robot {
proxy_pass http://127.0.0.1:9999/robot;
proxy_redirect default;
proxy_set_header Cookie $http_cookie;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
index index.html index.htm;
}

nginx相关命令

1
2
3
4
5
重启nginx:/usr/nginx/sbin/nginx -s reopen
重新加载配置文件:/usr/nginx/sbin/nginx -s reload
启动:/usr/nginx/sbin/nginx
关闭:/usr/nginx/sbin/nginx -s stop
指定配置文件:/usr/nginx/sbin/nginx -c nginx.conf

安装supervisor

1
2
3
tar -xf  supervisor-3.3.3.tar.gz
cd supervisor-3.3.3
python setup.py install

服务端指令:supervisord
客户端指令:supervisorctl
服务端执行配置文件:supervisord -c /home/startsh/supervisord.conf

supervisor的配置文件里加入

1
2
3
4
5
6
7
8
9
[program:HT-NGINX]
directory = /home/startsh
command = /usr/nginx/sbin/nginx -c /home/startsh/nginx.conf ; 指定启动文件
autostart=true
autorestart=true ;如果NGINX异常退出,则重启
startretries=3 ;最大重启次数
redirect_stderr=true ; 重定向输出的日志
stdout_logfile = /var/log/supervisord/HT-NGINX.log
loglevel=info

supervisor常用命令

客户端执行配置文件:supervisorctrl -c /home/startsh/supervisord.conf

1
2
3
4
5
6
7
8
help # 查看帮助
status # 查看程序状态
reread # 更新配置,不重启应用
update # 重启配置改动的应用
stop program_name # 关闭 指定的程序
start program_name # 启动 指定的程序
restart program_name # 重启 指定的程序
tail -f program_name # 查看 该程序的日志

阿里云、腾讯云SSH经常自动断开

修改 /etc/ssh/sshd_config

1
2
ClientAliveInterval 30
ClientAliveCountMax 86400

重启sshd服务:

1
/bin/systemctl restart sshd.service

启动nginx时报错

1
2
[root@VM_81_66_centos ~]# /usr/nginx/sbin/nginx  -c /home/startsh/nginx.conf
nginx: [emerg] open() "/home/startsh/mime.types" failed (2: No such file or directory) in /home/startsh/nginx.conf:18

解决方法:

1
2
3
http {
include /usr/nginx/conf/mime.types; //补全,填写含有mime.types的路径
default_type application/octet-stream;

本文标题:CentOS7部署supervisor和nginx

文章作者:HT

发布时间:2018年03月19日 - 22:03

最后更新:2018年03月19日 - 23:03

原始链接:http://7ht.gitee.io/2018/03/19/CentOS7部署supervisor和nginx/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。