CentOS8 初始环境下安装 Nginx
前言
此教程在刚刚安装成功的 CentOS 8 系统上安装 Nginx。CentOS 8 安装在VMware Fusion 虚拟机上。
CentOS 8 系统初始操作
1、升级所有软件包
执行命令 yum update -y,该命令会升级所有软件包,也会升级软件和系统内核;
2、更新 yum 源
cd /etc/yum.repos.d/
mkdir bak
mv *.repo bak
wget http://mirrors.aliyun.com/repo/Centos-8.repo
yum clean all # 清除 yum 仓库缓存
yum makecache # 生成新的 yum 仓库缓存
3、安装基础软件
yum -y install epel-release # 安装扩展工具包 yum 源
yum install net-tools wget nscd lsof # 安装工具
yum -y install gcc pcre-devel zlib-devel openssl-devel libxml2-devel libxslt-devel gd-devel GeoIP-devel jemalloc-devel perl-devel perl-ExtUtils-Embed
安装 Nginx
1、下载 nginx
mkdir -p opt/data/source
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar zxmf nginx-1.18.0.tar.gz

2、安装 nginx
编译 nginx 源码文件需要通过编译配置命令 configure 进行编译配置,编译时可以根据需要带上配置参数;
./configure --help ,查看配置参数项;
--prefix=PATH # 默认值是 /usr/local/,用于指定编译后代码安装目录

2.1、编译 ./configure
./configure \
--with-threads \
--with-file-aio \
--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_auth_request_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-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre-jit
参数说明:
--with-threads enable thread pool support
--with-file-aio enable file AIO support
--with-http_ssl_module enable ngx_http_ssl_module
--with-http_v2_module enable ngx_http_v2_module
--with-http_realip_module enable ngx_http_realip_module
--with-http_addition_module enable ngx_http_addition_module
--with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module
--with-http_image_filter_module=dynamic enable dynamic ngx_http_image_filter_module
--with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module
--with-http_sub_module enable ngx_http_sub_module
--with-http_dav_module enable ngx_http_dav_module
--with-http_flv_module enable ngx_http_flv_module
--with-http_mp4_module enable ngx_http_mp4_module
--with-http_gunzip_module enable ngx_http_gunzip_module
--with-http_gzip_static_module enable ngx_http_gzip_static_module
--with-http_auth_request_module enable ngx_http_auth_request_module
--with-http_random_index_module enable ngx_http_random_index_module
--with-http_secure_link_module enable ngx_http_secure_link_module
--with-http_degradation_module enable ngx_http_degradation_module
--with-http_slice_module enable ngx_http_slice_module
--with-http_stub_status_module enable ngx_http_stub_status_module
--with-stream=dynamic enable dynamic TCP/UDP proxy module
--with-stream_ssl_module enable ngx_stream_ssl_module
--with-stream_realip_module enable ngx_stream_realip_module
--with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
--with-stream_ssl_preread_module enable ngx_stream_ssl_preread_module
--with-compat dynamic modules compatibility
--with-pcre-jit build PCRE with JIT compilation support

2.2、安装
make && make install
安装之后才会有安装目录,安装前编译后只是指定安装目录 /usr/local/nginx;
默认安装目录是:/usr/local/nginx,可以在编译时用 --prefix=PATH 参数指定安装目录;
可以根据需要在编译时加减参数;
2.3、添加第三方模块
nginx 功能是模块化的;
可以在编译时通过参数 --add-module=PATH(指定静态模块) / --add-dynamic-module=PATH(指定动态模块)指定第三方模块;
编译后在 make install 安装时会把第三方模块安装进来;