阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nginx1.10.2稳定版本tcp四层负载安装配置讲解

458次阅读
没有评论

共计 13041 个字符,预计需要花费 33 分钟才能阅读完成。

nginx1.10.2(2016.10.18)是最新稳定版,适合线上运行,最新开发版为 1.11.8(2016.12.27)
系统版本 CentOS6.8 64 位,所有依赖都是系统 rpm 包,由于 epel-release 的 nginx 包不是最新的稳定版本所以选择源码包安装 nginx 通过源码编译安装

1、安装编译所需工具
  yum groupinstall “Development Tools”
  yum install wget

2、到官网下载最新的源代码(https://nginx.org/en/)
  cd /usr/local/src
  wget http://nginx.org/download/nginx-1.10.2.tar.gz
  tar zxvf nginx-1.10.2.tar.gz

3、安装依赖包
  yum install zlib-devel openssl-devel pcre-devel
  zlib: 为 nginx 提供 gzip 模块,需要 zlib 库支持,传输数据打包,省流量(但消耗资源)
  openssl: 为 nginx 提供 ssl 功能
  pcre: 为支持地址重写 rewrite 功能

4、创建用来运行 nginx 的用户及组
  groupadd -g 58 www
  useradd -u 58 -g 58 -M www -s /sbin/nologin - g 参数为 www 用户指定了一个组。- M 参数保证其不 自动生成 home 目录。

5、编译源代码
  先使用./configure –help 查看编译帮助:
  我的线上编译参数,默认开启的不用写
  ./configure –with-http_ssl_module –with-http_v2_module –with-http_realip_module –with-http_stub_status_module –with-stream  –with-stream_ssl_module –with-pcre
./configure –help
 
  –help                            print this message
 
  –prefix=PATH                      set installation prefix #Nginx 安装的根路径, 默认为 /usr/local/nginx。
  –sbin-path=PATH                  set nginx binary pathname #指定 nginx 二进制文件的路径, 默认为 PATH/sbin/nginx。
  –modules-path=PATH                set modules path #Perl 模块位置
  –conf-path=PATH                  set nginx.conf pathname #设定 nginx 配置文件地址,默认为 PATH/conf/nginx.conf。
  –error-log-path=PATH              set error log pathname #错误文件路径,默认为 PATH/logs/error.log。
  –pid-path=PATH                    set nginx.pid pathname # master 进程 pid 写入的文件位置, 通常在 var/run 下,默认为 PATH/logs/nginx.pid。
  –lock-path=PATH                  set nginx.lock pathname #共享存储器互斥锁文件路径
 
  –user=USER                        set non-privileged user for worker processes #指定程序运行时的非特权用户
  –group=GROUP                      set non-privileged group for worker processes #指定程序运行时的非特权用户组
 
  –build=NAME                      set build name #编译名称
  –builddir=DIR                    set build directory #指向编译目录
 
  –with-select_module              enable select module 允许或不允许开启 SELECT 模式,如果 configure 没有找到合适的模式,比如,kqueue(sun os)、epoll(linux kenel 2.6+)、rtsig(实时信号)
  –without-select_module            disable select module 禁用 select 模块支持
  –with-poll_module                enable poll module 启用 poll 模块支持(功能与 select 相同,与 select 特性相同,为一种轮询模式, 不推荐在高载环境下使用)
  –without-poll_module              disable poll module 禁用 poll 模块支持
 
  –with-threads                    enable thread pool support
 
  –with-file-aio                    enable file AIO support #为 freeBSD4.3+ 和 linux2.6.22+ 系统启用异步 io
 
  –with-ipv6                        enable IPv6 support #启用 ipv6 支持
   
# 默认禁用的模块
  –with-http_ssl_module            enable ngx_http_ssl_module #使支持 https 请求,需已安装 openssl
  –with-http_v2_module              enable ngx_http_v2_module #启用 HTTP V2
  –with-http_realip_module          enable ngx_http_realip_module #此模块支持显示真实来源 IP 地址,主要用于 NGINX 做前端负载均衡服务器使用
  –with-http_addition_module        enable ngx_http_addition_module #输出过滤器, 使你能够在请求经过一个 location 前或后时在该 location 本身添加内容
  –with-http_xslt_module            enable ngx_http_xslt_module #这个模块是一个过滤器,它可以通过 XSLT 模板转换 XML 应答
  –with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module 
  –with-http_image_filter_module    enable ngx_http_image_filter_module #图像过滤器, 在将图像投递到客户之前进行处理(需要 libgd 库)
  –with-http_image_filter_module=dynamic
                                    enable dynamic ngx_http_image_filter_module 
  –with-http_geoip_module          enable ngx_http_geoip_module #创建基于与 MaxMind GeoIP 相配的客户端地址
  –with-http_geoip_module=dynamic  enable dynamic ngx_http_geoip_module
  –with-http_sub_module            enable ngx_http_sub_module #这个模块可以能够在 nginx 的应答中搜索并替换文本
  –with-http_dav_module            enable ngx_http_dav_module #为文件和目录指定权限,限制不同类型的用户对于页面有不同的操作权限
  –with-http_flv_module            enable ngx_http_flv_module #这个模块支持对 FLV(flash)文件的拖动播放
  –with-http_mp4_module            enable ngx_http_mp4_module #支持 H.264/AAC 文件为伪流媒体
  –with-http_gunzip_module          enable ngx_http_gunzip_module #对于不支持 gzip 编码的客户, 该模块用于为客户解压缩预压缩内容
  –with-http_gzip_static_module    enable ngx_http_gzip_static_module #这个模块在一个预压缩文件传送到开启 Gzip 压缩的客户端之前检查是否已经存在以“.gz”结尾的压缩文件,这样可以防止文件被重复压缩
  –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 #该模块提供一种机制, 它会将一个哈希值链接到一个 url 中, 因此, 只有那些使用正确的密码能够计算链接
  –with-http_degradation_module    enable ngx_http_degradation_module #允许在内存不足的情况下返回 204 或 444 码
  –with-http_slice_module          enable ngx_http_slice_module 
  –with-http_stub_status_module    enable ngx_http_stub_status_module #取得一些 nginx 的运行状态,输出的状态信息可使用 RRDtool 或类似的工具绘制成图
# 默认启用的模块
  –without-http_charset_module      disable ngx_http_charset_module #重新编码 web 页面
  –without-http_gzip_module        disable ngx_http_gzip_module #同 -with-http_gzip_static_module 功能一样
  –without-http_ssi_module          disable ngx_http_ssi_module #提供在输入端处理处理服务器包含文件(SSI)的过滤器,目前支持 SSI 命令的列表是不完整的
  –without-http_userid_module      disable ngx_http_userid_module #用来处理用来确定客户端后续请求的 cookies
  –without-http_access_module      disable ngx_http_access_module #供了一个简单的基于主机的访问控制。允许 / 拒绝基于 ip 地址
  –without-http_auth_basic_module  disable ngx_http_auth_basic_module #可以使用用户名和密码基于 http 基本认证方法来保护你的站点或其部分内容
  –without-http_autoindex_module    disable ngx_http_autoindex_module #自动生成目录列表,只在 ngx_http_index_module 模块未找到索引文件时发出请求。
  –without-http_geo_module          disable ngx_http_geo_module #创建一些变量,其值依赖于客户端的 IP 地址
  –without-http_map_module          disable ngx_http_map_module #使用任意的键 / 值对设置配置变量
  –without-http_split_clients_module disable ngx_http_split_clients_module #用来基于某些条件划分用户。条件如:ip 地址、报头、cookies 等等
  –without-http_referer_module      disable ngx_http_referer_module #用来过滤请求,拒绝报头中 Referer 值不正确的请求
  –without-http_rewrite_module      disable ngx_http_rewrite_module #允许使用正则表达式改变 URI,并且根据变量来转向以及选择配置
  –without-http_proxy_module        disable ngx_http_proxy_module #有关代理服务器
  –without-http_fastcgi_module      disable ngx_http_fastcgi_module #允许 Nginx 与 FastCGI 进程交互,并通过传递参数来控制 FastCGI 进程工作。
  –without-http_uwsgi_module        disable ngx_http_uwsgi_module #用来使用 uwsgi 协议,uWSGI 服务器相关
  –without-http_scgi_module        disable ngx_http_scgi_module #用来启用 SCGI 协议支持,SCGI 协议是 CGI 协议的替代。
  –without-http_memcached_module    disable ngx_http_memcached_module #用来提供简单的缓存,以提高系统效率
  –without-http_limit_conn_module  disable ngx_http_limit_conn_module #允许你对于一个地址进行连接数的限制用一个给定的 session 或一个特定的事件
  –without-http_limit_req_module    disable ngx_http_limit_req_module #允许你对于一个地址进行请求数量的限制用一个给定的 session 或一个特定的事件
  –without-http_empty_gif_module    disable ngx_http_empty_gif_module #在内存中常驻了一个 1 * 1 的透明 GIF 图像,可以被非常快速的调用
  –without-http_browser_module      disable ngx_http_browser_module #用来创建依赖于请求报头的值
  –without-http_upstream_hash_module
                                    disable ngx_http_upstream_hash_module #用于简单的负载均衡
  –without-http_upstream_ip_hash_module
                                    disable ngx_http_upstream_ip_hash_module 
  –without-http_upstream_least_conn_module
                                    disable ngx_http_upstream_least_conn_module 
  –without-http_upstream_keepalive_module
                                    disable ngx_http_upstream_keepalive_module
  –without-http_upstream_zone_module
                                    disable ngx_http_upstream_zone_module
 
  –with-http_perl_module            enable ngx_http_perl_module #这个模块允许 nginx 使用 SSI 调用 perl 或直接执行 perl(使用会降低性能)
  –with-http_perl_module=dynamic    enable dynamic ngx_http_perl_module
  –with-perl_modules_path=PATH      set Perl modules path #设定 perl 模块路径
  –with-perl=PATH                  set perl binary pathname #设定 perl 库文件路径
 
  –http-log-path=PATH              set http access log pathname #设定 access log 路径
  –http-client-body-temp-path=PATH  set path to store http client request body temporary files #设定 http 客户端请求临时文件路径
  –http-proxy-temp-path=PATH        set path to store http proxy temporary files #设定 http 代理临时文件路径
  –http-fastcgi-temp-path=PATH      set path to store http fastcgi temporary files #设定 http fastcgi 临时文件路径
  –http-uwsgi-temp-path=PATH        set path to store http uwsgi temporary files #设定 http uwsgi 临时文件路径
  –http-scgi-temp-path=PATH        set path to store http scgi temporary files #设定 http scgi 临时文件路径
 
  –without-http                    disable HTTP server #完全禁用 http 模块, 如果只想支持 mall, 可以使用此项设置
  –without-http-cache              disable HTTP cache #在使用 upstream 模块时,nginx 能够配置本地缓存内容, 此选项可禁用缓存
 
  –with-mail                        enable POP3/IMAP4/SMTP proxy module #激活 POP3/IMAP4/SMTP 代理模块, 默认未激活
  –with-mail=dynamic                enable dynamic POP3/IMAP4/SMTP proxy module
  –with-mail_ssl_module            enable ngx_mail_ssl_module #SMTP 可以使用 SSL/TLS. 配置已经定义了 HTTP SSL 模块,但是不支持客户端证书检测
  –without-mail_pop3_module        disable ngx_mail_pop3_module #启用 mail 模块后, 单独禁用 pop3 模块
  –without-mail_imap_module        disable ngx_mail_imap_module #启用 mail 模块后, 单独禁用 imap 模块
  –without-mail_smtp_module        disable ngx_mail_smtp_module #启用 mail 模块后, 单独禁用 smtp 模块
 
  –with-stream                      enable TCP/UDP proxy module
  –with-stream=dynamic              enable dynamic TCP/UDP proxy module
  –with-stream_ssl_module          enable ngx_stream_ssl_module
  –without-stream_limit_conn_module disable ngx_stream_limit_conn_module
  –without-stream_access_module    disable ngx_stream_access_module
  –without-stream_upstream_hash_module
                                    disable ngx_stream_upstream_hash_module
  –without-stream_upstream_least_conn_module
                                    disable ngx_stream_upstream_least_conn_module
  –without-stream_upstream_zone_module
                                    disable ngx_stream_upstream_zone_module
 
  –with-google_perftools_module    enable ngx_google_perftools_module #调试用,剖析程序性能瓶颈
  –with-cpp_test_module            enable ngx_cpp_test_module
 
  –add-module=PATH                  enable external module #启用外部模块支持
  –add-dynamic-module=PATH          enable dynamic external module
# 编译相关的参数
  –with-cc=PATH                    set C compiler pathname #如果想设置一个不在默认 path 下的 c 编译器
  –with-cpp=PATH                    set C preprocessor pathname #设置 c 预处理器的相对路径
  –with-cc-opt=OPTIONS              set additional C compiler options #设置 C 编译器参数
  –with-ld-opt=OPTIONS              set additional linker options #包含连接库的路径和运行路径
  –with-cpu-opt=CPU                build for the specified CPU, valid values:pentium, pentiumpro, pentium3, pentium4,athlon, opteron, sparc32, sparc64, ppc64 #指定编译的 CPU
 
  –without-pcre                    disable PCRE library usage #禁用 pcre 库
  –with-pcre                        force PCRE library usage #启用 pcre 库
  –with-pcre=DIR                    set path to PCRE library sources #指向 pcre 库文件目录
  –with-pcre-opt=OPTIONS            set additional build options for PCRE #在编译时为 pcre 库设置附加参数
  –with-pcre-jit                    build PCRE with JIT compilation support
 
  –with-md5=DIR                    set path to md5 library sources #指向 md5 库文件目录
  –with-md5-opt=OPTIONS            set additional build options for md5 #在编译时为 md5 库设置附加参数
  –with-md5-asm                    use md5 assembler sources #使用 md5 汇编源
 
  –with-sha1=DIR                    set path to sha1 library sources #指向 sha1 库目录
  –with-sha1-opt=OPTIONS            set additional build options for sha1 #在编译时为 sha1 库设置附加参数
  –with-sha1-asm                    use sha1 assembler sources #使用 sha1 汇编源
 
  –with-zlib=DIR                    set path to zlib library sources #指向 zlib 库目录
  –with-zlib-opt=OPTIONS            set additional build options for zlib #在编译时为 zlib 设置附加参数
  –with-zlib-asm=CPU                use zlib assembler sources optimized for the specified CPU, valid values: pentium, pentiumpro #为指定的 CPU 使用 zlib 汇编源进行优化
 
  –with-libatomic                  force libatomic_ops library usage # 为原子内存的更新操作的实现提供一个架构
  –with-libatomic=DIR              set path to libatomic_ops library sources #指向 libatomic_ops 安装目录
 
  –with-openssl=DIR                set path to OpenSSL library sources #指向 openssl 安装目录
  –with-openssl-opt=OPTIONS        set additional build options for OpenSSL #在编译时为 openssl 设置附加参数
 
  –with-debug                      enable debug logging #启用 debug 日志

6,编译汇总
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx modules path: “/usr/local/nginx/modules”
nginx configuration prefix: “/usr/local/nginx/conf”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”

7,编译安装
  编译
  make
  安装
  make install
  加入 PATH 
  ln -s /usr/local/nginx/sbin/nginx  /usr/sbin/nginx
  核查版本信息
123456 nginx -V
nginx version: nginx/1.10.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: –with-http_ssl_module –with-http_v2_module –with-http_realip_module –with-http_stub_status_module –with-stream –with-stream_ssl_module –with-pcre

8,简单配置
我这次主要使用到 tcp 四层负载,后续可能涉及到 https http2 等,所以编译时添加了那些参数。
nginx.conf 配置如下:
user  www www;
worker_processes  auto;
worker_cpu_affinity auto;
error_log  logs/error.log  error;
pid        logs/nginx.pid;
worker_rlimit_nofile 653600;
events
{
  use epoll;
  worker_connections 655350;
}
stream {
    upstream server {
        hash $remote_addr consistent;
        server 172.16.1.11:8081 weight=1 max_fails=3 fail_timeout=10s;
        server 172.16.1.22:8081 weight=1 max_fails=3 fail_timeout=10s;
    }
    server {
        listen 8081;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass server;
    }
}

CentOS 7.2 下编译安装 PHP7.0.10+MySQL5.7.14+Nginx1.10.1  http://www.linuxidc.com/Linux/2016-09/134804.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

Nginx 的 500,502,504 错误解决方法 http://www.linuxidc.com/Linux/2015-03/115507.htm

CentOS 7 编译安装 Nginx1.10.2 脚本启动失败解决思路 http://www.linuxidc.com/Linux/2017-01/139794.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-01/139965.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计13041字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19350
评论数
4
阅读量
7912685
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
如何免费使用强大的Nano Banana Pro?附赠邪修的用法

如何免费使用强大的Nano Banana Pro?附赠邪修的用法

如何免费使用强大的 Nano Banana Pro?附赠邪修的用法 前言 大家好,我是星哥,今天来介绍谷歌的 ...
星哥带你玩飞牛NAS-1:安装飞牛NAS

星哥带你玩飞牛NAS-1:安装飞牛NAS

星哥带你玩飞牛 NAS-1:安装飞牛 NAS 前言 在家庭和小型工作室场景中,NAS(Network Atta...
还在找免费服务器?无广告免费主机,新手也能轻松上手!

还在找免费服务器?无广告免费主机,新手也能轻松上手!

还在找免费服务器?无广告免费主机,新手也能轻松上手! 前言 对于个人开发者、建站新手或是想搭建测试站点的从业者...
从“纸堆”到“电子化”文档:用这个开源系统打造你的智能文档管理系统

从“纸堆”到“电子化”文档:用这个开源系统打造你的智能文档管理系统

从“纸堆”到“电子化”文档:用这个开源系统打造你的智能文档管理系统 大家好,我是星哥。公司的项目文档存了一堆 ...
颠覆 AI 开发效率!开源工具一站式管控 30+大模型ApiKey,秘钥付费+负载均衡全搞定

颠覆 AI 开发效率!开源工具一站式管控 30+大模型ApiKey,秘钥付费+负载均衡全搞定

  颠覆 AI 开发效率!开源工具一站式管控 30+ 大模型 ApiKey,秘钥付费 + 负载均衡全...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
开发者福利:免费 .frii.site 子域名,一分钟申请即用

开发者福利:免费 .frii.site 子域名,一分钟申请即用

  开发者福利:免费 .frii.site 子域名,一分钟申请即用 前言 在学习 Web 开发、部署...
把小米云笔记搬回家:飞牛 NAS 一键部署,小米云笔记自动同步到本地

把小米云笔记搬回家:飞牛 NAS 一键部署,小米云笔记自动同步到本地

把小米云笔记搬回家:飞牛 NAS 一键部署,小米云笔记自动同步到本地 大家好,我是星哥,今天教大家在飞牛 NA...
星哥带你玩飞牛NAS-16:飞牛云NAS换桌面,fndesk图标管理神器上线!

星哥带你玩飞牛NAS-16:飞牛云NAS换桌面,fndesk图标管理神器上线!

  星哥带你玩飞牛 NAS-16:飞牛云 NAS 换桌面,fndesk 图标管理神器上线! 引言 哈...
安装并使用谷歌AI编程工具Antigravity(亲测有效)

安装并使用谷歌AI编程工具Antigravity(亲测有效)

  安装并使用谷歌 AI 编程工具 Antigravity(亲测有效) 引言 Antigravity...
150元打造低成本NAS小钢炮,捡一块3865U工控板

150元打造低成本NAS小钢炮,捡一块3865U工控板

150 元打造低成本 NAS 小钢炮,捡一块 3865U 工控板 一块二手的熊猫 B3 工控板 3865U,搭...