ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## centos下yum安装 nginx的RPM包可以在epel中找到,但版本较老;官方制作的RPM源较新 ### 官方RPM源 ~~~ [nginx] name=nginx repo baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1 ~~~ 将“OS”替换为“rhel” 或“centos”,将“OSRELEASE” 替换为“6” 或 “7”; ### [官方RPM仓库][1] ### RPM依赖 ~~~ yum install -y pcre-devel openssl-devel zlib-devel pcre zlib openssl ~~~ ### 安装 ~~~ yum install -y nginx ~~~ ### rpm编译参数 [编译时默认支持的模块][2] [编译时默认不支持的模块][3] [第三方模块][4] `nginx -V` ~~~ --user=nginx --group=nginx --prefix=/etc/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 --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-compat # 动态模块兼容 --with-file-aio # 支持异步IO --with-threads # 支持线程池 --with-http_addition_module # 在响应报文的前后增加内容 --with-http_auth_request_module # 基于 subrequest 的结果的实现客户端授权 --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module # 在客户端不支持gzip情况下使用gunzip --with-http_gzip_static_module # 支持压缩 --with-http_random_index_module # 请求以/结尾,则在目录中任选一个作为index文件 --with-http_realip_module --with-http_secure_link_module --with-http_slice_module # 允许将请求拆分成子请求,每个 subrequest 返回一定范围的响应。提供更有效的缓存的大文件。 --with-http_ssl_module # 支持ssl --with-http_stub_status_module # 提供基本的状态信息 --with-http_sub_module # 将响应中的指定内容替换 --with-http_v2_module # 支持http2 --with-mail # 支持mail --with-mail_ssl_module # 支持mail的ssl --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie ~~~ ## centos下编译安装 ### 下载 http://nginx.org/download/nginx-xxx.tar.gz ### 解压 ~~~ # tar xf nginx-1.12.1.tar.gz ~~~ ### 建立用户(-r 为系统用户) ~~~ # groupadd -r -g 110 nginx # useradd -r -g 110 -u 110 nginx ~~~ ### 解决依赖关系 ~~~ yum install -y pcre-devel openssl-devel zlib-devel pcre zlib openssl ~~~ ### 编译参数 ~~~ --user=nginx \ --group=nginx \ --prefix=/usr/local/nginx \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --with-compat \ --with-http_addition_module \ --with-http_auth_request_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_realip_module \ --with-http_secure_link_module \ --with-http_slice_module \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_sub_module ~~~ ## 第三方模块 [如何使用第三方模块官方文档][5] ~~~ ./configure ... --add-module=/usr/build/nginx-rtmp-module ./configure ... --add-dynamic-module=/path/to/module ~~~ 这里测试了[echo-nginx-module][6],目前的版本还未支持较新版本的nginx,因此使用nginx1.10.3搭配echo-nginx-module v0.60 [1]:http://nginx.org/packages/centos/ [2]:https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#modules_default [3]:https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#modules_not_default [4]:https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#modules_third_party [5]:https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#modules_third_party [6]:https://github.com/openresty/echo-nginx-module