Centos7安裝nginx(編譯安裝)

1.下載nginx
進入nginx官網,下載需要的版本的nginx包,以tar.gz結尾的文件。
假設文件名爲nginx-1.14.2.tar.gz,並且放在/usr/local。
2.安裝依賴環境

yum install -y openssl openssl-devel
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y gcc-c++

3.安裝nginx

cd /usr/local
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
mkdir /usr/local/nginx
./configure --with-http_ssl_module --prefix=/usr/local/nginx --with-http_sub_module
make
make install
vim /usr/lib/systemd/system/nginx.service

插入以下內容

[Unit]
Description=Nginx
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
WorkingDirectory=/usr/local/nginx
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

保存文件並退出

systemctl daemon-reload
systemctl enable nginx
systemctl start nginx
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章