centos编译安装nginx

作者 : 开心源码 本文共3983个字,预计阅读时间需要10分钟 发布时间: 2022-05-13 共196人阅读

源码下载

安装wget并下载nginx源码包, 去 http://nginx.org/download/ 可以找到历史版本的包

[root@localhost ~]# yum install -y wget && wget http://nginx.org/download/nginx-1.17.9.tar.gz

新添加客户

groupadd wwwuseradd -g www www

安装依赖环境

# pcre:rewrite模块依赖,zlib:gzip模块需要[root@localhost ~]# yum install -y gcc pcre pcre-devel zlib zlib-devel 

部分编译参数说明

参数形容
–prefix定义nginx安装路径
–sbin-path定义nginx可执行文件路径
–modules-pathnginx模块路径
–conf-pathnginx配置文件路径
–error-log-path、–http-log-path错误和访问日志路径
–with-openssl定义编译使用的openssl,默认为系统自带openssl
–with-http_ssl_modulessl模块

开始编译

[root@localhost ~]# ./configure --prefix=/usr/local/nginx \--sbin-path=/usr/sbin/nginx \--modules-path=/usr/lib64/nginx/modules \--conf-path=/usr/local/nginx/nginx.conf \--error-log-path=/usr/local/nginx/error.log \--http-log-path=/usr/local/nginx/access.log \--pid-path=/usr/local/nginx/nginx.pid \--lock-path=/usr/local/nginx/nginx.lock \--http-client-body-temp-path=/usr/local/nginx/client_temp \--http-proxy-temp-path=/usr/local/nginx/proxy_temp \--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \--http-scgi-temp-path=/usr/local/nginx/scgi_temp \--user=www \--group=www \--with-compat \--with-file-aio \--with-threads \--with-http_addition_module \--with-http_auth_request_module \--with-http_dav_module \--with-http_flv_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_mp4_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 \--with-http_v2_module \--with-mail \--with-mail_ssl_module \--with-stream \--with-stream_realip_module \--with-stream_ssl_module \--with-stream_ssl_preread_module

image

上面的编译是使用了系统默认的openssl,假如想使用更高版本的openssl进行编译的话。可以加上--with-openssl=openssl安装路径来自己设置。高版本的openssl安装可以参考 这篇文章 .

--with-openssl 参数尽管可以指定 OpenSSL 路径,但只支持 OpenSSL 的源代码,不支持已编译好的 OpenSSL。每回升级 nginx 都要重新编译 OpenSSL 很麻烦 。以下是处理方案

打开nginx源码解压目录下的auto/lib/openssl/conf,找到所有带.openssl的行

CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"

改成下面的样子,去掉.openssl/

CORE_INCS="$CORE_INCS $OPENSSL/include"CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"

进行编译

[root@localhost ~]# ./configure --prefix=/usr/local/nginx \--sbin-path=/usr/sbin/nginx \--modules-path=/usr/lib64/nginx/modules \--conf-path=/usr/local/nginx/nginx.conf \--error-log-path=/usr/local/nginx/error.log \--http-log-path=/usr/local/nginx/access.log \--pid-path=/usr/local/nginx/nginx.pid \--lock-path=/usr/local/nginx/nginx.lock \--http-client-body-temp-path=/usr/local/nginx/client_temp \--http-proxy-temp-path=/usr/local/nginx/proxy_temp \--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \--http-scgi-temp-path=/usr/local/nginx/scgi_temp \--user=www \--group=www \--with-compat \--with-file-aio \--with-threads \--with-http_addition_module \--with-http_auth_request_module \--with-http_dav_module \--with-http_flv_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_mp4_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 \--with-http_v2_module \--with-mail \--with-mail_ssl_module \--with-stream \--with-stream_realip_module \--with-stream_ssl_module \--with-openssl=/usr/local/openssl \--with-stream_ssl_preread_module

image

安装

[root@localhost ~]# make && make install

安装完成后,检查详细信息

# /usr/sbin/nginx是编译时--sbin-path定义的[root@localhost ~]# /usr/sbin/nginx -V

1586415658983.png

总结

以上是nginx编译安装全过程。编译安装相比yum费时,但是可以很好的根据需求自行添加或者去掉某些模块,有高度的定制性。但是正式使用yum安装的也能够满足需求,需要yum安装的可以看这篇文章

参考

https://www.sinosky.org/compile-nginx-with-a-custom-openssl-library.html

https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » centos编译安装nginx

发表回复