下载
http://nginx.org/download/nginx-1.16.1.tar.gz
依赖
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
添加运行用户
groupadd -f www
useradd -g www www
# 如果没有可能会报错nginx: [emerg] getpwnam(“www”) failed
编译
tar xvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module
make && make install
# http_stub_status_module 状态监控
# http_ssl_module 配置https
# stream 配置tcp得转发
# http_gzip_static_module 压缩
# http_sub_module 替换请求
设置配置文件
mkdir -p /etc/nginx/{conf,conf.d}
mv /usr/local/nginx/conf/* /etc/nginx/conf/
开机自启service
cat > /etc/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStartPost=/bin/sleep 0.1
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /etc/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable nginx
systemctl start nginx
网友评论