在centos上编译nginx
nginx源码包下载
wget -O /root/ http://nginx.org/download/nginx-1.27.4.tar.gz
系统版本及内核
CentOS Linux release 7.6.1810 (Core)
3.10.0-957.el7.x86_64
仓库源配置
此处使用的是阿里云镜像源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
编译环境安装
yum groupinstall -y "Development Tools"
yum install -y pcre-devel zlib-devel openssl-devel
yum install -y libxslt libxslt-devel
yum install -y gd gd-devel
yum install -y perl-ExtUtils-Embed
yum install -y google-perftools google-perftools-devel
编辑和安装
tar xf /root/nginx-1.27.4.tar.gz
cd /nginx-1.27.4
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx \
--user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module \
--with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module \
--with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module \
--with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic \
--with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module \
--with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module \
--with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit \
--with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g \
-pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 \
-grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro \
-specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
make
make install
生成必要的文件
mkdir -p /var/lib/nginx/tmp/client_body
chown -R nginx.nginx /var/lib/nginx/tmp/client_body
nginx.service配置
vim /lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重载服务,启动服务
systemctl daemon-reload
systemctl restart nginx.service
附:文中提到的软件及仓库源官网
https://developer.aliyun.com/mirror/centos
http://nginx.org/en/download.html
本文来自博客园,作者:赛博狗尾草,转载请注明原文链接:https://www.cnblogs.com/gpysir/p/18805813
浙公网安备 33010602011771号