Centos7 nginx的编译和安装

安装前的准备

安装依赖包

# yum -y install pcre pcre-devel openssl openssl-devel gcc-c++ autoconf automake zlib-devel libxml2 libxml2-dev libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data

注:本人曾在centos 7.6 minimal(自带包非常少)中安装这些依赖并成功编译通过

创建nginx用户和用户组

# adduser nginx

下载并解压nginx源码

Download-nginx中下载nginx的源码包并解压(本次使用的是nginx-1.14.0)

# tar -xvzf nginx-1.14.0.tar.gz

编译nginx

cd到解压后的源码目录

# cd nginx-1.14.0

编译配置

# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx \ --with-file-aio --with-ipv6 \ --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module \ --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic \ --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module \ --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module \ --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module \ --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic \ --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module \ --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module \ --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic \ --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module \ --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module \ --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module \ --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module \ --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-threads \

编译并安装

# make # make install

创建Systemd服务

SYSTEMDDIR=/usr/lib/systemd/system SERVICEFILE=nginx.service cat >${SYSTEMDDIR}/${SERVICEFILE} <<EOF [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.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=/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target EOF

设置开机启动

systemctl enable nginx.service

启动、关闭、重启nginx

systemctl start nginx
systemctl stop nginx
systemctl restart nginx

本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。转载请注明: 作者staneyffer,首发于我的博客,原文链接: https://chengfy.com/post/15


Nginxnginx
2019-04-02
载入评论中....