源码安装nginx
1. For ubuntu:18.04
apt -y install build-essential libtool libpcre3 libpcre3-dev zlib1g-dev openssl net-tools curl wget
wget -P /tmp http://nginx.org/download/nginx-1.18.0.tar.gz
tar -xf /tmp/nginx-1.18.0.tar.gz -C /usr/local/src
cd /usr/local/src/nginx-1.18.0 && ./configure --prefix=/usr/local/nginx
make && make insatll
增强性能或功能需要优化或使用其他方案
2. For Centos7
yum -y install gcc pcre-devel openssl-devel zlib-devel
useradd -s /sbin/nologin nginx -M
wget -P /tmp http://nginx.org/download/nginx-1.18.0.tar.gz
tar -xf /tmp/nginx-1.18.0.tar.gz -C /usr/local/src
cd /usr/local/src/nginx-1.18.0
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
make && make install
chown -R nginx.nginx /usr/local/nginx
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl enable --now nginx
PS:
Ubuntu安装Nginx
CentOS系统安装openresty