centos7安装Nginx添加自启动
编译安装Nginx-1.16,安装在/usr/local/nginx
安装依赖
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ make
配置安装模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
编译安装
make && make install
配置
cd /usr/lib/systemd/system
vim nginx.service
cat nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
输入 systemctl start nginx 启动
添加到开机启动: 输入 systemctl start nginx 启动
查看 此状态 输入 systemctl status nginx.service