1. 程式人生 > 其它 >CentOS 安裝 nginx 教程

CentOS 安裝 nginx 教程

CentOS 安裝 nginx 教程

下載安裝包

cd /usr/local
wget http://nginx.org/download/nginx-1.19.8.tar.gz

安裝依賴

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

解壓縮安裝包

tar -zxvf nginx-1.19.8.tar.gz
cd /usr/local/nginx-1.19.8/

編譯執行

./configure --with-http_ssl_module
make
make install

刪除解壓包

cd ..
rm -fr nginx-1.19.8

建立快捷方式

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx -f

安裝服務

cd /usr/lib/systemd/system/
vi 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