CentOS 7.x編譯安裝Nginx ,設為開機啟動項
阿新 • • 發佈:2018-11-15
1、安裝
1、安裝nginx的依賴
yum -y install openssl openssl-devel
yum -y install pcre-devel
2、下載nginx-1.10.3.tar.gz原始碼並解壓至/root/ http://nginx.org/download/nginx-1.10.3.tar.gz
tar zvxf /root/nginx-1.10.3.tar.gz mv /root/nginx-1.10.3/ /root/nginx #進入到nginx解壓路徑後,使用下面的命令配置nginx及其module cd /root/nginx/ ./configure --prefix=/usr/local/nginx --with-http_ssl_module
3、編譯並安裝
make
make install
2、新增服務
vi /usr/lib/systemd/system/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
3、啟動服務並新增開機啟動
systemctl start nginx.service
systemctl enable nginx.service
systemctl status nginx.service