centos7配置nginx开机自启动

centos7安装openresty

cd /usr/local/src/openresty
yum -y install pcre-devel openssl openssl-devel
yum install -y gcc gcc-c++ zlib-devel pcre-devel openssl-devel readline-devel
wget https://openresty.org/download/openresty-1.9.7.5.tar.gz
tar xzvf openresty-1.9.7.5.tar.gz
cd openresty-1.9.7.5
./configure --prefix=/usr/local/openresty --with-luajit --with-http_iconv_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module
gmake && gmake install
#### start
/usr/local/openresty/nginx/sbin/nginx -p /data/www/src/online/
#### reload
/usr/local/openresty/nginx/sbin/nginx -p /data/www/src/online/ -s reload

systemd启动nginx多应用文件进程

more /usr/lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server

[Service]
ExecStart=/root/start.sh

[Install]
WantedBy=multi-user.target

nginx多应用文件启动脚本

more /root/start.sh 
#!/bin/bash
/usr/local/openresty/nginx/sbin/nginx -c /data/www/src/online/conf/nginx.conf -t
/usr/local/openresty/nginx/sbin/nginx -c /data/www/src/online_gray/conf/nginx.conf -t
/usr/local/openresty/nginx/sbin/nginx -c /data/www/src/online/conf/nginx.conf
/usr/local/openresty/nginx/sbin/nginx -c /data/www/src/online_gray/conf/nginx.conf

chmod +x /root/start.sh

systemctl daemon-reload #生效配置文件重载
systemctl enable nginx.service #设置开机启动
systemctl list-unit-files |grep nginx #查看nginx应用开机状态
systemctl start nginx.service #查看nginx应用启动状态
systemctl status nginx.service

systemd配置nginx开机启动

more /usr/lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server

[Service]
Type=forking
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -c /data/www/src/online/conf/nginx.conf -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx -c /data/www/src/online/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

猜你喜欢

转载自blog.51cto.com/11676712/2537309