nignx 编译安装

2022-06-24  本文已影响0人  晨曦_zdq
  groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx

./configure --prefix=/usr/local/nginx \
    --with-http_stub_status_module \
    --user=nginx --group=nginx \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/run/nginx.pid \
    --with-pcre \
    --with-http_ssl_module \
    --without-mail_pop3_module \
    --without-mail_imap_module \
    --with-http_gzip_static_module \
    --with-stream

报错1: ./configure: error: C compiler cc is not found
apt install gcc
报错2: ./configure: error: the HTTP rewrite module requires the PCRE library.
apt install libpcre3-dev
报错3: ./configure: error: SSL modules require the OpenSSL library.
apt install libssl-dev
报错4: ./configure: error: the HTTP gzip module requires the zlib library.
apt install zlib1g-dev

apt install make
make && make install

脚本

#!/bin/bash
# nginx source make install by taxue
# 2021-12-28 v1.0

nginx_url='https://nginx.org/download/nginx-1.20.2.tar.gz'
nginx_bao=${nginx_url##*/}
bao_dir='/usr/local/src'

ping -c 1 -i.2 www.baidu.com
if [ $? -ne 0 ];then
        echo "网络不通,请检查网络!"
        exit 100
fi

[ -f ${bao_dir}/${nginx_bao} ] || wget $nginx_url -P $bao_dir/
cd $bao_dir
tar -xzvf $nginx_bao
cd `echo $nginx_url |awk -F'/' '{print $NF}' | awk -F'.tar' '{print $1}'`

id nginx || useradd -r  -s /bin/false -M nginx

apt update
apt -y install make gcc libpcre3-dev libssl-dev zlib1g-dev

./configure --prefix=/usr/local/nginx \
    --with-http_stub_status_module \
    --user=nginx --group=nginx \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/run/nginx.pid \
    --with-pcre \
    --with-http_ssl_module \
    --without-mail_pop3_module \
    --without-mail_imap_module \
    --with-http_gzip_static_module \
    --with-stream
make && make install

# system 服务管理
# 注意nginx二进制文件和配置文件位置
echo '[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"

[Install]
WantedBy=multi-user.target' > /lib/systemd/system/nginx.service

systemctl daemon-reload
systemctl start nginx
curl localhost:80
上一篇下一篇

猜你喜欢

热点阅读