nginx 1.14.2编译安装

nginx 1.14.2编译安装

1.配置nginx编译环境

环境:CentOs 7.5

#部署依赖环境
更新yum
yum update -y
安装gcc
yum install -y gcc-c++
安装pcre
yum install -y pcre pcre-devel
安装zlib
yum install -y zlib zlib-devel
安装OpenSSL
yum install -y openssl openssl-devel

2.下载nginx-1.14.2源码包

#进入临时文件夹
cd /tmp
#下载安装包
git clone https://github.com/JohnsonCydia/nginx.git
#进入安装目录并解压然后进入解压目录
cd /tmp/nginx && tar -zxvf nginx-1.14.2.tar.gz && cd /tmp/nginx/nginx-1.14.2

3.编译安装

#configure配置(配置文件详解在文末)
./configure --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 --user=nginx --group=nginx --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 --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
#安装
make && make install

4.启动前配置

创建nginx缓存文件夹
mkdir -p /var/cache/nginx
#配置systemctl支持
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

5.启动nginx并配置开机启动

systemctl start nginx
systemctl enable nginx

附录:nginx编译安装详解(官网google机翻)

原文链接:http://nginx.org/en/docs/configure.html
从Sources构建nginx
使用该configure命令配置构建。它定义了系统的各个方面,包括允许nginx用于连接处理的方法。最后它创建了一个Makefile。

该configure命令支持以下参数:

–help
打印帮助信息。
–prefix=path
定义将保留服务器文件的目录。同一目录也将用于设置的所有相对路径 configure(库源路径除外)和nginx.conf配置文件中。它/usr/local/nginx默认设置为目录。
–sbin-path=path
设置nginx可执行文件的名称。此名称仅在安装期间使用。默认情况下,该文件已命名 prefix/sbin/nginx。
–modules-path=path
定义将安装nginx动态模块的目录。默认情况下,prefix/modules使用该目录。
–conf-path=path
设置nginx.conf配置文件的名称。如果需要,可以始终使用不同的配置文件启动nginx,方法是在命令行参数中指定它 。默认情况下,该文件已命名 。 -c fileprefix/conf/nginx.conf
–error-log-path=path
设置主要错误,警告和诊断文件的名称。安装后,可以nginx.conf使用error_log指令在配置文件中 更改文件名 。默认情况下,该文件已命名 prefix/logs/error.log。
–pid-path=path
设置nginx.pid将存储主进程的进程ID 的文件的名称。安装后,可以nginx.conf使用pid指令在配置文件中 更改文件名 。默认情况下,该文件已命名 prefix/logs/nginx.pid。
–lock-path=path
为锁定文件的名称设置前缀。安装后,可以nginx.conf使用lock_file指令在配置文件中 始终更改该值 。默认情况下,该值为 prefix/logs/nginx.lock。
–user=name
设置非特权用户的名称,其凭据将由工作进程使用。安装后,可以nginx.conf使用user指令在配置文件中 更改名称 。默认用户名是nobody。
–group=name
设置工作进程将使用其凭据的组的名称。安装后,可以nginx.conf使用user指令在配置文件中 更改名称 。默认情况下,组名称设置为非特权用户的名称。
–build=name
设置可选的nginx构建名称。
–builddir=path
设置构建目录。
–with-select_module
–without-select_module
启用或禁用构建允许服务器使用该select()方法的模块。如果平台似乎不支持更合适的方法(如kqueue,epoll或/ dev / poll),则会自动构建此模块。
–with-poll_module
–without-poll_module
启用或禁用构建允许服务器使用该poll()方法的模块。如果平台似乎不支持更合适的方法(如kqueue,epoll或/ dev / poll),则会自动构建此模块。
–with-threads
允许使用 线程池。
–with-file-aio
允许 在FreeBSD和Linux上使用 异步文件I / O(AIO)。
–with-http_ssl_module
允许构建一个模块,将HTTPS协议支持添加 到HTTP服务器。默认情况下不构建此模块。需要OpenSSL库来构建和运行此模块。
–with-http_v2_module
可以构建一个支持HTTP / 2的模块 。默认情况下不构建此模块。
–with-http_realip_module
允许构建ngx_http_realip_module 模块,该 模块将客户端地址更改为在指定的头字段中发送的地址。默认情况下不构建此模块。
–with-http_addition_module
允许构建ngx_http_addition_module 模块,该 模块在响应之前和之后添加文本。默认情况下不构建此模块。
–with-http_xslt_module
–with-http_xslt_module=dynamic
允许构建 使用一个或多个XSLT样式表转换XML响应的 ngx_http_xslt_module模块。默认情况下不构建此模块。该libxml2的和 的libxslt库需要构建和运行此模块。
–with-http_image_filter_module
–with-http_image_filter_module=dynamic
可以构建ngx_http_image_filter_module 模块,该 模块可以转换JPEG,GIF,PNG和WebP格式的图像。默认情况下不构建此模块。
–with-http_geoip_module
–with-http_geoip_module=dynamic
允许构建ngx_http_geoip_module 模块,该 模块根据客户端IP地址和预编译的MaxMind数据库创建变量 。默认情况下不构建此模块。
–with-http_sub_module
允许构建ngx_http_sub_module 模块,该 模块通过将一个指定的字符串替换为另一个来修改响应。默认情况下不构建此模块。
–with-http_dav_module
支持构建ngx_http_dav_module 模块,该 模块通过WebDAV协议提供文件管理自动化。默认情况下不构建此模块。
–with-http_flv_module
支持构建ngx_http_flv_module 模块,该 模块为Flash Video(FLV)文件提供伪流服务器端支持。默认情况下不构建此模块。
–with-http_mp4_module
支持构建ngx_http_mp4_module 模块,该 模块为MP4文件提供伪流服务器端支持。默认情况下不构建此模块。
–with-http_gunzip_module
对于不支持“gzip”编码方法的客户端, 可以构建ngx_http_gunzip_module 模块,该 模块使用“ Content-Encoding: gzip” 解压缩响应。默认情况下不构建此模块。
–with-http_gzip_static_module
允许构建ngx_http_gzip_static_module 模块,该 模块允许使用“ .gz”文件扩展名而不是常规文件发送预压缩文件。默认情况下不构建此模块。
–with-http_auth_request_module
允许构建ngx_http_auth_request_module 模块,该 模块基于子请求的结果实现客户端授权。默认情况下不构建此模块。
–with-http_random_index_module
允许构建ngx_http_random_index_module 模块,该 模块处理以斜杠字符(’ /’)结尾的请求,并选择目录中的随机文件作为索引文件。默认情况下不构建此模块。
–with-http_secure_link_module
可以构建 ngx_http_secure_link_module 模块。默认情况下不构建此模块。
–with-http_degradation_module
可以构建 ngx_http_degradation_module模块。默认情况下不构建此模块。
–with-http_slice_module
允许构建 将请求拆分为子请求的 ngx_http_slice_module模块,每个模块都返回一定范围的响应。该模块提供了更有效的大响应缓存。默认情况下不构建此模块。
–with-http_stub_status_module
可以构建ngx_http_stub_status_module 模块,该 模块提供对基本状态信息的访问。默认情况下不构建此模块。
–without-http_charset_module
禁用构建ngx_http_charset_module 模块,该 模块将指定的字符集添加到“Content-Type”响应头字段,并且还可以将数据从一个字符集转换为另一个字符集。
–without-http_gzip_module
禁用构建压缩 HTTP服务器响应的模块。zlib库是构建和运行此模块所必需的。
–without-http_ssi_module
禁用构建ngx_http_ssi_module 模块,该 模块在通过它的响应中处理SSI(服务器端包含)命令。
–without-http_userid_module
禁用构建ngx_http_userid_module 模块,该 模块设置适合客户端识别的cookie。
–without-http_access_module
禁用构建ngx_http_access_module 模块,该 模块允许限制对某些客户端地址的访问。
–without-http_auth_basic_module
禁用构建ngx_http_auth_basic_module 模块,该 模块允许通过使用“HTTP基本身份验证”协议验证用户名和密码来限制对资源的访问。
–without-http_mirror_module
禁用构建ngx_http_mirror_module 模块,该 模块通过创建后台镜像子请求来实现原始请求的镜像。
–without-http_autoindex_module
禁用构建ngx_http_autoindex_module 模块,该 模块处理以斜杠字符(’ /’)结尾的请求,并在ngx_http_index_module模块找不到索引文件的情况下生成目录列表 。
–without-http_geo_module
禁用构建ngx_http_geo_module 模块,该 模块使用取决于客户端IP地址的值创建变量。
–without-http_map_module
禁用构建ngx_http_map_module 模块,该 模块使用取决于其他变量值的值创建变量。
–without-http_split_clients_module
禁用构建ngx_http_split_clients_module 模块,该 模块为A / B测试创建变量。
–without-http_referer_module
禁用构建ngx_http_referer_module 模块,该 模块可以阻止对“Referer”头字段中具有无效值的请求访问站点。
–without-http_rewrite_module
禁用构建允许HTTP服务器 重定向请求和更改请求URI的模块。需要PCRE库来构建和运行此模块。
–without-http_proxy_module
禁用构建HTTP服务器 代理模块。
–without-http_fastcgi_module
禁用构建 将请求传递给FastCGI服务器的 ngx_http_fastcgi_module模块。
–without-http_uwsgi_module
禁用构建 将请求传递给uwsgi服务器的 ngx_http_uwsgi_module模块。
–without-http_scgi_module
禁用构建 将请求传递给SCGI服务器的 ngx_http_scgi_module模块。
–without-http_grpc_module
禁用构建 将请求传递给gRPC服务器的 ngx_http_grpc_module模块。
–without-http_memcached_module
禁用构建ngx_http_memcached_module 模块,该 模块从memcached服务器获取响应。
–without-http_limit_conn_module
禁用构建ngx_http_limit_conn_module 模块,该 模块限制每个密钥的连接数,例如,来自单个IP地址的连接数。
–without-http_limit_req_module
禁用构建ngx_http_limit_req_module 模块,该 模块限制每个密钥的请求处理速率,例如,来自单个IP地址的请求的处理速率。
–without-http_empty_gif_module
禁用构建发出单像素透明GIF的模块 。
–without-http_browser_module
禁用构建ngx_http_browser_module 模块,该 模块创建的值的变量值取决于“User-Agent”请求标头字段的值。
–without-http_upstream_hash_module
禁用构建实现散列 负载平衡方法的模块 。
–without-http_upstream_ip_hash_module
禁用构建实现ip_hash 负载平衡方法的模块 。
–without-http_upstream_least_conn_module
禁用构建实现least_conn 负载平衡方法的模块 。
–without-http_upstream_keepalive_module
禁用构建一个模块,该模块提供 到上游服务器的连接缓存。
–without-http_upstream_zone_module
禁用构建模块,该模块可以将上游组的运行时状态存储在共享内存 区域中。
–with-http_perl_module
–with-http_perl_module=dynamic
可以构建 嵌入式Perl模块。默认情况下不构建此模块。
–with-perl_modules_path=path
定义一个将保留Perl模块的目录。
–with-perl=path
设置Perl二进制文件的名称。
–http-log-path=path
设置HTTP服务器的主要请求日志文件的名称。安装后,可以nginx.conf使用access_log指令在配置文件中 更改文件名 。默认情况下,该文件已命名 prefix/logs/access.log。
–http-client-body-temp-path=path
定义用于存储保存客户端请求主体的临时文件的目录。安装后,可以nginx.conf使用client_body_temp_path 指令在配置文件中 更改目录 。默认情况下,该目录已命名 prefix/client_body_temp。
–http-proxy-temp-path=path
定义一个目录,用于存储临时文件和从代理服务器接收的数据。安装后,可以nginx.conf使用proxy_temp_path 指令在配置文件中 更改目录 。默认情况下,该目录已命名 prefix/proxy_temp。
–http-fastcgi-temp-path=path
定义一个目录,用于存储从FastCGI服务器接收的数据的临时文件。安装后,可以nginx.conf使用fastcgi_temp_path 指令在配置文件中 更改目录 。默认情况下,该目录已命名 prefix/fastcgi_temp。
–http-uwsgi-temp-path=path
定义一个目录,用于存储从uwsgi服务器接收的数据的临时文件。安装后,可以nginx.conf使用uwsgi_temp_path 指令在配置文件中 更改目录 。默认情况下,该目录已命名 prefix/uwsgi_temp。
–http-scgi-temp-path=path
定义用于存储临时文件的目录,其中包含从SCGI服务器接收的数据。安装后,可以nginx.conf使用scgi_temp_path 指令始终在配置文件中 更改目录 。默认情况下,该目录已命名 prefix/scgi_temp。
–without-http
禁用HTTP服务器。
–without-http-cache
禁用HTTP缓存。
–with-mail
–with-mail=dynamic
启用POP3 / IMAP4 / SMTP 邮件代理服务器。
–with-mail_ssl_module
允许构建一个模块,将 SSL / TLS协议支持添加 到邮件代理服务器。默认情况下不构建此模块。需要OpenSSL库来构建和运行此模块。
–without-mail_pop3_module
禁用邮件代理服务器中的POP3协议。
–without-mail_imap_module
禁用邮件代理服务器中的IMAP协议。
–without-mail_smtp_module
禁用邮件代理服务器中的SMTP协议。
–with-stream
–with-stream=dynamic
允许构建 流模块 以进行通用TCP / UDP代理和负载平衡。默认情况下不构建此模块。
–with-stream_ssl_module
可以构建一个模块, 为流模块添加 SSL / TLS协议支持。默认情况下不构建此模块。需要OpenSSL库来构建和运行此模块。
–with-stream_realip_module
启用构建ngx_stream_realip_module 模块,该 模块将客户端地址更改为PROXY协议头中发送的地址。默认情况下不构建此模块。
–with-stream_geoip_module
–with-stream_geoip_module=dynamic
允许构建ngx_stream_geoip_module 模块,该 模块根据客户端IP地址和预编译的MaxMind数据库创建变量 。默认情况下不构建此模块。
–with-stream_ssl_preread_module
允许构建ngx_stream_ssl_preread_module 模块,该 模块允许从ClientHello 消息中提取信息 而不终止SSL / TLS。默认情况下不构建此模块。
–without-stream_limit_conn_module
禁用构建ngx_stream_limit_conn_module 模块,该 模块限制每个密钥的连接数,例如,来自单个IP地址的连接数。
–without-stream_access_module
禁用构建ngx_stream_access_module 模块,该 模块允许限制对某些客户端地址的访问。
–without-stream_geo_module
禁用构建ngx_stream_geo_module 模块,该 模块使用取决于客户端IP地址的值创建变量。
–without-stream_map_module
禁用构建ngx_stream_map_module 模块,该 模块根据其他变量的值创建值。
–without-stream_split_clients_module
禁用构建ngx_stream_split_clients_module 模块,该 模块为A / B测试创建变量。
–without-stream_return_module
禁用构建ngx_stream_return_module 模块,该 模块将一些指定值发送到客户端,然后关闭连接。
–without-stream_upstream_hash_module
禁用构建实现散列 负载平衡方法的模块 。
–without-stream_upstream_least_conn_module
禁用构建实现least_conn 负载平衡方法的模块 。
–without-stream_upstream_zone_module
禁用构建模块,该模块可以将上游组的运行时状态存储在共享内存 区域中。
–with-google_perftools_module
可以构建ngx_google_perftools_module 模块,该 模块可以使用Google Performance Tools分析nginx工作进程 。该模块适用于nginx开发人员,默认情况下不构建。
–with-cpp_test_module
可以构建 ngx_cpp_test_module模块。
–add-module=path
启用外部模块。
–add-dynamic-module=path
启用外部动态模块。
–with-compat
实现动态模块兼容性。
–with-cc=path
设置C编译器的名称。
–with-cpp=path
设置C预处理器的名称。
–with-cc-opt=parameters
设置将添加到CFLAGS变量的其他参数。在FreeBSD下使用系统PCRE库时, --with-cc-opt="-I /usr/local/include" 应该指定。如果select()需要增加支持的文件数,也可以在此处指定,例如: --with-cc-opt="-D FD_SETSIZE=2048"。
–with-ld-opt=parameters
设置将在链接期间使用的其他参数。在FreeBSD下使用系统PCRE库时, --with-ld-opt="-L /usr/local/lib" 应该指定。
–with-cpu-opt=cpu
支持按指定的CPU建设: pentium,pentiumpro, pentium3,pentium4, athlon,opteron, sparc32,sparc64, ppc64。
–without-pcre
禁用PCRE库的使用。
–with-pcre
强制使用PCRE库。
–with-pcre=path
设置PCRE库源的路径。库分发(版本4.4 - 8.43)需要从PCRE站点下载 并提取。其余的由nginx ./configure和 make。完成。该位置指令和 ngx_http_rewrite_module 模块中的正则表达式支持需要该库 。
–with-pcre-opt=parameters
为PCRE设置其他构建选项。
–with-pcre-jit
使用“即时编译”支持(1.1.12,pcre_jit指令)构建PCRE库 。
–with-zlib=path
设置zlib库源的路径。需要从zlib站点下载并提取库分发(版本1.1.3 - 1.2.11) 。其余的由nginx ./configure和 make。完成。ngx_http_gzip_module模块需要该库 。
–with-zlib-opt=parameters
为zlib设置其他构建选项。
–with-zlib-asm=cpu
使得能够使用指定的CPU中的一个优化的zlib汇编源程序: pentium,pentiumpro。
–with-libatomic
强制libatomic_ops库使用。
–with-libatomic=path
设置libatomic_ops库源的路径。
–with-openssl=path
设置OpenSSL库源的路径。
–with-openssl-opt=parameters
为OpenSSL设置其他构建选项。
–with-debug
启用调试日志。
参数用法示例(所有这些都需要在一行中输入):

./configure
–sbin-path = / usr / local / nginx / nginx
–conf-path = / usr / local / nginx / nginx.conf
–pid-path = / usr / local / nginx / nginx.pid
- -with-http_ssl_module
–with-pcre = … / pcre-8.43
–with-zlib = … / zlib-1.2.11
配置完成后,使用编译和安装nginx make。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值