Linux命令 Nginx


原文链接: Linux命令 Nginx

Nginx怎样部署SSL证书
nginx运维与架构
nginx服务器安装及配置文件详解
Nginx 配置文件详解
Nginx RTMP 模块 nginx-rtmp-module 指令详解
使用Nginx+FFMPEG搭建HLS直播转码服务器
nginx搭建支持http和rtmp协议的流媒体服务器
RTMP流媒体播放过程
m3u8-segmenter
Nginx安装
root与alias的区别
nginx配置location总结及rewrite规则写法
nginx应用总结(1)--基础认识和应用配置 - 散尽浮华 - 博客园
nginx服务器安装及配置文件详解 - Sean's Notes - SegmentFault
Nginx.org 文档 - 文集 - 简书
翻译 nginx 的 server names

Web服务器Nginx多方位优化策略 - 运维生存时间

Nginx 中文文档
######

https://github.com/winshining/nginx-http-flv-module rtmp组件

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /usr/share/nginx/html/;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                autoindex on;
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
        
        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

解决 nginx: [emerg] "load_module" directive is specified too late in /etc/nginx/nginx.conf:13

load_module 是需要在每个 block (包括 events、http、stream、mail)之前进行加载并运行的,虽然说 /etc/nginx/nginx.conf 是声明式的配置文件,但是必须这样声明在一定程度也有利于告诉开发者其顺序的重要性吧。

user  nginx;
worker_processes  4;

load_module "modules/ngx_http_upsync_module.so";

events {
    worker_connections  10240;
}
http {
}

小技巧 tips

nginx 仅通过检查请求首部中的 HOST 字段来决定让哪个虚拟主机处理访问请求

禁止浏览器缓存

`add_header Cache-Control 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0';`

nginx 暴力的方式就是清掉浏览器的缓存

在本地开发的时候,经常会碰到缓存引起的莫名其妙的问题,最暴力的方式就是清掉浏览器的缓存,或者使用Ctrl + F5,Shift + F5强制刷新页面

有时候按了好几下,缓存还是清不掉,只能暂时禁用浏览器静态资源缓存了

location ~.*.(js|css|html|png|jpg)$
{

add_header Cache-Control no-cache;

}
现在,按F5就行了

nginx 实现服务端同一域名下部署多个vue项目。

修改vue生成参数

  1. index.html文件修改
    添加
  2. config/index.js文件修改
    修改 assetsPublicPath: '/子目录名/'
  3. src/router/index.js文件修改
    添加 base: '/子目录名/'

Nginx配置

index index.html
location /子目录名 {
        root /home/vue
        try_files $uri $uri/ @router;
        }

location @router  {
        rewrite ^.*$ /子目录名/index.html last;
        }

nginx 列出目录

    location /logs {
        root /docker/;
        autoindex on;
        autoindex_localtime on;
        autoindex_exact_size off;
    }

nginx 忽略favicon.ico日志

favicon.ico占用nginx error_log日志大量信息,把我们真正需要查看的日志给覆盖。因此这里,我们通过log_not_found off关闭它。

location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
  1. 网上有看到一句说:注意error_log off并不能关闭日志记录功能,它将日志文件写入一个文件名为off的文件中,如果你想关闭错误日志记录功能,应使用以下配置:error_log /dev/null crit;
    off位置在/usr/local/nginx/off,即nginx的安装目录下

  2. log_not_found off改成error_log off效果也一样,不同的是写成error_log off是将错误日志输出到off文件,而log_not_found则是关闭日志。

    nginx 设置文件返回格式

    add_header Content-Type 'text/html; charset=utf-8';

nginx 解决跨域问题

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, DELETE, PUT, PATCH, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type, api_key, Authorization";
# add_header Access-Control-Allow-Headers X-Requested-With;

nginx 强制启用 HSTS

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header Strict-Transport-Security max-age=2592000;

Nginx 实现代理 WebSocket 设置Upgrade和Connection响应头。

Nginx 根据Upgrade(即$http_upgrade)来设置Connection:

如果请求头中有Upgrade,就直接设置到响应头中,并把Connection设置为upgrade。

例如 WebSocket 请求头会带上 Upgrade: websocket,则响应头有
Upgrade: websocket
Connection: upgrade

否则把Connection设置为close。如普通HTTP请求。

map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

server {
  listen 8000;
  location ~* /ws {
    proxy_pass http://localhost:3000;  

    proxy_read_timeout 604800;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
  }
}

nginx location 中 alias 和 root 区别

  1. alias 要配置访问 /aa 到 /var/www/hello.test.com/index.html ,你应该使用 alias 而不是 root
  2. root 要配置访问 /aa 到 /var/www/hello.test.com/aa/index.html 则使用root 会将匹配路径带入URI
  3. 配置子目录应该闭合,不要使用 /aa ,应该使用 /aa/ ; /aa 用于文件匹配
  4. alias后面必须要用“/”结束,否则会找不到文件的; 而root则可有可无
  5. 在 / 中配置root,在 /other 中配置alias是一个好习惯。

    index index.html index.htm;
    ## 下面两个都是访问 uri "/download/lzkp.apk" 的配置
    location /download {
        ## /usr/share/nginx/lzkp.apk
        alias /usr/share/nginx/;      
        autoindex on;
        autoindex_localtime on;
        autoindex_exact_size off;
    }
    location /download {
        ## /usr/share/nginx/download/lzkp.apk
        root /usr/share/nginx/;             
        index index.html index.htm;
    }
    
    

禁用php脚本解析

location ~* ^/uploads/.*.(php|php5)$ {
      deny all;
}

https://regexper.com
. : 匹配除换行符以外的任意字符
\d :匹配数字

? : 重复0次或1次

  • : 重复1次或更多次
  • : 重复0次或更多次

^ : 匹配字符串的开始
$ : 匹配字符串的介绍
{n} : 重复n次
{n,} : 重复n次或更多次
[c] : 匹配单个字符c
[a-z] : 匹配a-z小写字母的任意一个

内置变量

$request            # HTTP请求行,如"GET / HTTP/1.1"
$request_method     # HTTP请求方法,如"GET"、"POST"
$request_uri        # HTTP请求URI,带查询参数
$request_filename   # HTTP请求文件,如"/path/to/index.html"
$content_type       # HTTP报头"Content-Type"字段
$content_length     # HTTP报头"Content-Length"字段
$http_cookie        # HTTP报头"Cookie"字段
$http_user_agent    # HTTP报头"User-Agent"字段

$server_protocol    # 服务器HTTP版本,如"HTTP/1.0"、"HTTP/1.1"
$server_name        # 服务器Host名
$server_addr        # 服务器IP地址
$server_port        # 服务器Port号

$remote_addr        # 客户端IP地址
$remote_port        # 客户端Port号
$remote_user        # 客户端User名(认证)

$scheme             # 请求的协议类型,如"http"、"https"
$host               # 请求的虚拟主机
$uri                # 请求的URI,不带参数
$args               # 请求的参数
$query_string       # 请求的参数,同 $args

$document_uri       # 请求的URI,不带参数,同 $uri
$document_root      # 请求的根目录

$status             # HTTP响应码,如 200

location匹配规则

  1. 语法规则(按优先级从高到低)(=) > (^~) > (~,~*) > ( ) > (/)

    = 精确匹配
    ^~ url路径匹配(一般用来匹配目录),nginx不对url做编码,因此请求为/static/20%/aa,可以被规则^~ /static/ /aa匹配到(注意是空格)
    ~ 为区分大小写的正则匹配
    ~* 为不区分大小写的正则匹配
    !~ 区分大小写不匹配的正则
    !~* 不区分大小写不匹配的正则
    ' ' 普通匹配
    @ 命名的 location,使用在内部定向时,例如 error_page, try_files
    / 通用匹配,任何请求都会匹配到。

Nginx下的rewrite规则

一.正则表达式匹配,其中:
~ 为区分大小写匹配
~* 为不区分大小写匹配
!~和!~* 分别为区分大小写不匹配及不区分大小写不匹配

二.文件及目录匹配,其中:
-f和!-f用来判断是否存在文件
-d和!-d用来判断是否存在目录
-e和!-e用来判断是否存在文件或目录
-x和!-x用来判断文件是否可执行

rewrite regex replacement [flag];

三.rewrite指令的最后一项参数为flag标记,四种flag标记:
注: 这里的地址栏url不变,只是针对站内的url地址而言,只要是url重写必定改变地址栏

  1. 为空 - 地址栏url不变;但是内容已经变化,也是永久性的重定向。地址栏url不变
  2. last - 地址栏url不变; 内部跳转,只对站内url重写有效. url重写后,停止处理后续rewrite指令集马上发起一个新的请求,再次进入server块,重试location匹配,超过10次匹配不到报500错误.
  3. break - 地址栏url不变; url重写后,停止处理后续rewrite指令集,并不在重新查找,直接使用当前资源,不再执行location里余下的语句,完成本次请求,
  4. redirect - 地址栏url重写; 返回302临时重定向,url会跳转,爬虫不会更新url。
  5. permanent - 地址栏url重写; 返回301永久重定向。url会跳转。爬虫会更新url。

1.last 相当于apache里面的[L]标记,表示rewrite。
2.break 本条规则匹配完成后,终止匹配,不再匹配后面的规则。
3.redirect 返回302临时重定向,浏览器地址会显示跳转后的URL地址。
4.permanent 返回301永久重定向,浏览器地址会显示跳转后的URL地址。

last的意思实际上是用户访问老地址时,服务器到新地址去抓取内容然后展现,可以理解为服务器内部做了个跳转,而外部地址不会改变。如果你想让浏览器直接去访问新地址,请用redirect

last break 区别 ###

相同点: 地址栏url均不会变化
last

重新将 rewrite 后的 url 在 server 标签中执行

break

将 rewrite 后的地址在当前 location 标签中执行

因此,在 server 标签中的 last 和 break 没区别,它们的区别只体现在 location 字段:
在 location 中,last 将返回 server 标签重新执行一遍;break 则只在当前 location 标签中执行一遍。

location /download/ {
    rewrite ^(/download/.*)/media/(.*)..*$ $1/mp3/$2.mp3 break;
    rewrite ^(/download/.*)/audio/(.*)..*$ $1/mp3/$2.ra break;
    return 403;
}

上面的正则表达式的一部分可以用圆括号,方便之后按照顺序用$1-$9来引用。
小括号()之间匹配的内容,可以在后面通过$1来引用,$2表示的是前面第二个()里的内容。正则里面容易让人困惑的是\转义特殊字符。

如果我们将类似URL/photo/123456 重定向到/path/to/photo/12/1234/123456.png
rewrite "/photo/([0-9]{2})([0-9]{2})([0-9]{2})"/path/to/photo/$1/$1$2/$1$2$3.png ;

如果一个URI匹配指定的正则表达式regex,URI就按照replacement重写。
rewrite按配置文件中出现的顺序执行。flags标志可以停止继续处理。
如果replacement以"http://"或"https://"开始,将不再继续处理,这个重定向将返回给客户端。
flag可以是如下参数
last 停止处理后续rewrite指令集,然后对当前重写的新URI在rewrite指令集上重新查找。
break 停止处理后续rewrite指令集,并不在重新查找,但是当前location内剩余非rewrite语句和location外的的非rewrite语句可以执行。
redirect 如果replacement不是以http:// 或https://开始,返回302临时重定向
permant 返回301永久重定向
最终完整的重定向URL包括请求scheme(http://,https://等),请求的server_name_in_redirect和 port_in_redirec三部分 ,说白了也就是http协议 域名 端口三部分组成。

nginx的全局变量 ngx_http_core_module模块提供的变量

匹配规则

rewrite 写在 server、location、if 字段中

~ # 正则匹配
~* # 正则匹配(忽略大小写)
!~ # 正则取反
!~* # 正则取反(忽略大小写)

-f和!-f # 判断是否为文件
-d和!-d # 判断是否为目录
-e和!-e # 判断文件是否存在
-x和!-x # 判断文件是否可执行

set # 设置变量
last # 完成rewrite
break # 终止匹配

return # 返回状态码
redirect # 返回302临时重定向
permanent # 返回301永久重定向

last break 区别

last

重新将 rewrite 后的 url 在 server 标签中执行

break

将 rewrite 后的地址在当前 location 标签中执行

因此,在 server 标签中的 last 和 break 没区别,它们的区别只体现在 location 字段:
在 location 中,last 将返回 server 标签重新执行一遍;break 则只在当前 location 标签中执行一遍。


## 服务端变量
$server_protocol [HTTP/1.1]         请求使用的协议,通常是HTTP/1.0或HTTP/1.1,
$server_addr     [192.168.4.129]    服务器地址,在完成一次系统调用后可以确定这个值,如:
$server_name     [blog.pytool.com]  服务器名称,                            
$server_port     [80]               请求到达服务器的端口号,                   
$scheme          [http]             HTTP方法(如http,https),              
## 客户端变量
$binary_remote_addr [\x0A\xE0B\x0E] 浏览器客户端ip(二进制)
$remote_addr        [192.168.4.2]   浏览器客户端ip
$remote_port        [50472]         浏览器客户端port
$remote_user        []              已经经过Auth Basic Module验证的用户名

## HTTP请求
$http_host      [123.132.252.2:23180] 对应客户端请求头中Host对应的值,包含端口号 Host:123.132.252.2:23180 `return 301 $scheme://$http_host/bi/;`
$host           [blog.pytool.com]    请求主机头字段,否则为服务器名称,如:强制跳转到https `rewrite ^(.*)$	https://$host$1	permanent;` 
$args           [_a=index&_m=show&count=10] 请求参数
$arg_PARAMETER  [$arg_site]  请求中某个参数的值,如/index.php?site=www.ttlsa.com,可以用$arg_site取得www.ttlsa.com这个值.
$is_args        ["?"]    如果有$args参数,这个变量等于”?”,否则等于""空值
$query_string   [_a=index&_m=show&count=10]    与$args相同
$document_uri   [/index.php]   与$uri相同,如:/index.php
$document_root  [/webserver/htdocs/dwz]    针对当前请求的根路径设置值 
$uri            [/index.php]
$request_uri    [/index.php?arg=baz] 包含请求参数的原始URI,但不包含主机名,不能修改。如:/index.php?_a=index&_m=show&count=10
$request            # HTTP请求行信息,如:"GET /?_a=index&_m=show&count=10 HTTP/1.1"
$request_method     # HTTP请求方法,如"GET"、"POST"
$request_filename [/path/to/index.html]   # HTTP请求文件的路径名,由root或alias和URI request组合而成,
$status             请求的响应状态码,如:200

## HTTP报头--Header
$content_type       # HTTP报头"Content-Type"字段
$content_length     # HTTP报头"Content-Length"字段
$http_cookie        # HTTP报头"Cookie"字段
$http_user_agent    # HTTP报头"User-Agent"字段

$body_bytes_sent    响应时送出的body字节数数量。即使连接中断,这个数据也是精确的,如:40
$content_length     请求头中的Content-length字段
$content_type       请求头中的Content-Type字段
$http_referer       引用地址
$http_user_agent    客户端agent信息,如:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
$hostname           如:centos53.localdomain
$http_cookie        客户端cookie信息
$cookie_COOKIE      cookie   COOKIE变量的值
$limit_rate         这个变量可以限制连接速率,0表示不限速
$realpath_root      如:/webserver/htdocs/dwz
$request_body       记录POST过来的数据信息
$request_body_file  客户端请求主体信息的临时文件名
$request_completion 如果请求结束,设置为OK. 当请求未结束或如果该请求不是请求链串的最后一个时,为空(Empty),如:OK


user www-data;
# worker_processes auto;
#启动进程,通常设置成和cpu的数量相等或者2倍于cpu的个数(具体结合cpu和内存)。默认为1
# 物理个数: grep "physical id" /proc/cpuinfo |sort|uniq|wc -l
# CPU核数: grep "cpu cores" /proc/cpuinfo|sort|uniq
# 逻辑CPU核数:grep "processor" /proc/cpuinfo|wc -l
worker_processes auto;
worker_cpu_affinity auto;


#工作模式以及连接数上限
events {

  # use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
  use epoll;
  worker_connections 65535; ## default: 1024 max_clients=worker_processes * worker_connections

  #在设置了反向代理的情况下,max_clients=worker_processes * worker_connections / 4
  #worker_connections 值的设置跟物理内存大小有关
  #因为并发受IO约束,max_clients的值须小于系统可以打开的最大文件数
  #而系统可以打开的最大文件数和内存大小成正比,一般1GB内存的机器上可以打开的文件数大约是10万左右
  #我们来看看360M内存的VPS可以打开的文件句柄数是多少:
  #$ cat /proc/sys/fs/file-max
  #输出 34336
  #32000 < 34336,即并发连接总数小于系统可以打开的文件句柄总数,这样就在操作系统可以承受的范围之内
  #所以,worker_connections 的值需根据 worker_processes 进程数目和系统可以打开的最大文件总数进行适当地进行设置
  #使得并发总数小于操作系统可以打开的最大文件数目
  #其实质也就是根据主机的物理CPU和内存进行配置
  #当然,理论上的并发总数可能会和实际有所偏差,因为主机还有其他的工作进程需要消耗系统资源。
  #ulimit -SHn 65535
}
worker_rlimit_nofile 65535;
#nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。
# sudo vi /etc/security/limits.conf
# root soft nofile 65535
# root hard nofile 65535
# * soft nofile 65535
# * hard nofile 65535

#全局的错误日志和日志级别[ debug | info | notice | warn | error | crit ]
#默认为/etc/nginx/logs/error.log
# error_log  logs/error.log;         默认:warn
# error_log  logs/error.log  notice;
error_log logs/error.log crit;
# pid        logs/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

# backlog=8192;       # 默认为511
# 2. 设定http服务器 http://nginx.org/en/docs/http/ngx_http_core_module.html
http {

  include mime.types; #文件扩展名与文件类型映射表
  default_type application/octet-stream; #默认文件类型
  #charset utf-8;                         #默认编码
  server_names_hash_bucket_size 128; #服务器名字的hash表大小
  server_tokens on; #隐藏nginx的版本号
  #autoindex on;                          #开启目录列表访问,合适下载服务器,默认关闭。

  ## 1. log
  #设定日志格式
  # log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  #                  '$status $body_bytes_sent "$http_referer" '
  #                  '"$http_user_agent" "$http_x_forwarded_for"';
  ## aliyun
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" $http_host '
                      '$status $request_length $body_bytes_sent "$http_referer" '
                      '"$http_user_agent"  $request_time $upstream_response_time';
 
  #access_log  logs/access.log  main;
  #access日志文件的路径,采用上面定义的main 格式记录

  # access_log  off;
  access_log logs/access.log ;

  ## 2. file
  sendfile on; #开启高效文件传输模式 默认开启状态on;
  #sendfile指令指定nginx是否调用sendfile函数来输出文件,减少用户空间到内核空间的上下文切换。对于普通应用设为 on,
  #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off ,以平衡磁盘与网络I/O处理速度,降低系统的负载。
  #注意:如果图片显示不正常把这个改成off。默认开启状态

  # 默认就是tcp_nopush,不需要特别指定 等效linux下的 tcp_cork
  tcp_nopush on; #多个小块数据包合并发送,这样有助于解决网络堵塞;
  # tcp_nodelay on;                         #立即发送小块数据
  #注意:当使用sendfile函数时,tcp_nopush才起作用,它和指令tcp_nodelay是互斥的。


  ## 3. cache
  open_file_cache max=100000 inactive=30s; #开文件缓存,默认值 off 可以避免重新打开同一文件带来的系统开销,节省响应时间。如需开启必须后接参数 max=数字,设置缓存元素的最大数量。当缓存溢出时,使用LRU(最近最少使用)算法删除缓存中的元素;可选参数 inactive=时间 设置超时,在这段时间内缓存元素如果没有被访问,将从缓存中删除
  open_file_cache_valid 30s; #检测正确信息的间隔时间
  open_file_cache_min_uses 2; #设置在由open_file_cache指令的inactive参数配置的超时时间内, 文件应该被访问的最小次数。如果访问次数大于等于此值,文件描述符会保留在缓存中,否则从缓存中删除。
  open_file_cache_errors on; #指定了当搜索一个文件时是否缓存错误信息,也包括再次给配置中添加文件。我们也包括了服务器模块,这些是在不同文件中定义的。如果你的服务器模块不在这些位置,你就得修改这一行来指定正确的位置。

  ## 4. Buffers
  # 当遇到超长的post请求或者get请求时,nginx会返回413、400、414等状态码,这是因为请求串长度超过了nginx默认的缓存大小或者请求串大小
  #Buffers:另一个很重要的参数为buffer,如果buffer太小,Nginx会不停的写一些临时文件,这样会导致磁盘不停的去读写.
  client_body_buffer_size 10m;  #客户端允许单个文件上传最大值 16k
  client_max_body_size 100m;   #设置客户端能够上传的文件大小,默认为1m
  client_header_buffer_size 4k; #用于设置客户端请求的Header头缓冲区大小,大部分情况1KB大小足够
  large_client_header_buffers 32 64k; #该指令用于设置客户端请求的Header头缓冲区大小

  ## 5. Timeouts
  #如果没有发送请求头和请求体,Nginx服务器会返回408错误或者request time out。
  client_header_timeout 12;  #置请求头超时时间,单位是秒
  client_body_timeout 12;    #请求体超时时间,单位是秒
  send_timeout 3600;         #客户端两次请求的超时时间。这个设置不会用于整个转发器,而是在两次客户端读取操作之间。如果在这段时间内,客户端没有读取任何数据,Nginx就会关闭连接。
  reset_timedout_connection on; #告诉nginx关闭不响应的客户端连接。这将会释放那个客户端所占有的内存空间。

  # keepalive_timeout参数很敏感,服务器将在这个超时时间过后关闭链接。长连接请求大量小文件的时候,可以减少重建连接的开销,但假如有大文件上传,120s内没上传完成会导致失败。如果设置时间过长,用户又多,长时间保持连接会占用大量资源。
  keepalive_requests 100; #一个客户端可以通过一个keepalive连接的请求次数
  keepalive_timeout 1800; #长连接超时时间,单位是秒 [太小的话大文件无法上传,太大nginx的错误日志(socket() failed (24: Too many open files) while connecting to upstream)]

  proxy_connect_timeout 3600;
  proxy_send_timeout 3600;
  proxy_read_timeout 3600;

  
  ## 6. FastCGI
  #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。
  #fastcgi_connect_timeout 300;
  #fastcgi_send_timeout 300;
  #fastcgi_read_timeout 300;
  #fastcgi_buffer_size 64k;
  #fastcgi_buffers 4 64k;
  #fastcgi_busy_buffers_size 128k;
  #fastcgi_temp_file_write_size 128k;

  ## 7. gzip
  #开启Gzip,gzip可以帮助Nginx减少大量的网络传输工作,另外要注意gzip_comp_level的设置,太高的话,Nginx服务会浪费CPU的执行周期。
  gzip on; #开启Gzip,gzip可以帮助Nginx减少大量的网络传输工作
  gzip_disable "MSIE [1-6].(?!.*SV1)"; #为指定的客户端禁用gzip功能。我们设置成IE6或者更低版本以使我们的方案能够广泛兼容。
  gzip_min_length 1k; #小于1K的文件不进行压缩
  gzip_buffers 4 16k; #4 16k 代表以16k为单位,按照原始数据大小以16k为单位的4倍申请内存
  gzip_static on; #告诉nginx在压缩资源之前,先查找是否有预先gzip处理过的资源。这样nginx就不用再压缩这些文件了
  #gzip_http_version 1.0;                 #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
  gzip_comp_level 4; #压缩等级 是1-9之间的任意数值,9是最慢但是压缩比最大的。太高的话,Nginx服务会浪费CPU的执行周期。
  gzip_proxied any; #允许或者禁止压缩基于请求和响应的响应流。我们设置为any,意味着将会压缩所有的请求。
  #gzip_vary on;
  #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
  gzip_types text/plain text/css text/x-component
  text/xml application/xml application/xhtml+xml application/json
  image/x-icon image/bmp image/svg+xml application/atom+xml
  text/javascript application/javascript application/x-javascript
  application/pdf application/postscript
  application/rtf application/msword
  application/vnd.ms-powerpoint application/vnd.ms-excel
  application/vnd.ms-fontobject application/vnd.wap.wml
  application/x-font-ttf application/x-font-opentype;


  ## 8. 开启限制IP连接数的时候需要使用
  #limit_zone crawler $binary_remote_addr 10m;
  limit_conn_zone $binary_remote_addr zone=addr:10m;
  # 要限制连接,必须先有一个容器对连接进行计数,zone=addr这个名字要跟后面的 limit_conn 一致,$binary_remote_addr, 用二进制来储存客户端的地址,10m可以存放16万个ip 一旦用完,server就一直是503
  limit_conn addr 100;      # 一个IP 最多同时开100连接


  # limit_conn_zone $binary_remote_addr zone=conn_ip:10m;
  # limit_conn_zone $server_name zone=conn_server:10m;
  # limit_conn conn_ip 50;  #限制某个IP来源的连接并发数,此处为5个
  # limit_conn conn_server 600; #限制某个虚拟服务器的总连接数,此处为600个

  # limit_req_zone $binary_remote_addr $request_uri zone=thre:3m rate=1r/s; #支持多个变量,比如限制同一 IP 访问同一 Url 的频率
  # limit_req zone=req_ip burst=5; #小为5的缓冲区, 当有大量请求过来时,超过了访问频次限制的请求可以先放到这个缓冲区内
  # limit_req_zone $binary_remote_addr zone=req_ip:10m rate=40r/s; #每个IP平均处理的请求频率为每秒40次

  # limit_conn_zone 设置用于保存各种key(比如当前连接数)的共享内存的参数。5m就是5兆字节,这个值应该被设置的足够大以存储(32K5)32byte状态或者(16K5)64byte状态。
  # limit_conn 为给定的key设置最大连接数。这里key是addr,我们设置的值是100,也就是说我们允许每一个IP地址最多同时打开有100个连接。
  # limit_rate:限制单个连接的带宽量。能够防止系统因一些客户端而超载,能确保所有用户都享用质量的服务
  # limit_req/limit_req_zone:这些指令用于限制正在被Nginx 处理的请求的比率。使用 limit_rate 能防止系统某几个客户端超载并且能确保所有客户获取高质量的服务。这些指令同样能提高安全性,尤其是登录页,通过限制请求率来做更适合人类用户的请求,减慢试图访问你应用的程序用户。

  ## 9. errors
  recursive_error_pages off;
  error_page 400 402 403 405 406 410 411 413 416 /40x.html;
  error_page 404 =410 /40x.html;
  error_page 443 =200 /test.png;
  open_log_file_cache max=1024 inactive=30s min_uses=3 valid=5m;
  #定义50x错误提示页面
  error_page 500 501 502 503 504 /50x.html;
  # location = /50x.html {
  #     #定义服务器的默认网站错误页面位置
  #     root   html;
  # }


  ### acl ###
  allow 10.0.0.0/8;
  allow 172.16.0.0/12;
  allow 192.168.0.0/16;
  # deny                    all;

  # Load modular configuration files from the /etc/nginx/conf.d directory.
  # See http://nginx.org/en/docs/ngx_core_module.html#include
  # for more information.
  include conf.d/*.conf;
  include sites-enabled/*.conf;


  server {

    listen 80 default_server;
    listen [::]:80 ipv6only=on default_server;
    server_name _;
    root /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include default.d/*.conf;

    location / {

    }

    error_page 404 /404.html;
    location = /40x.html {

    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {

    }
  }

  # Settings for a TLS enabled server.

  # server {
  #
  #   listen 443 ssl http2 default_server;
  #   listen [::]:443 ssl http2 default_server;
  #   server_name _;
  #   root /usr/share/nginx/html;
  #
  #
  #   ssl on;
  #   ssl_certificate cert/server.crt;
  #   ssl_certificate_key cert/server.key;
  #   ssl_session_timeout 10m;
  #   ssl_prefer_server_ciphers on;
  #   ssl_session_cache shared:SSL:10m;
  #   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  #   ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  #
  #   # Load configuration files for the default server block.
  #   include default.d/*.conf;
  #
  #   location / {
  #
  #     rewrite ^(.*)$	http://$host$1	permanent; #强制跳转到http
  #   }
  #
  #   error_page 404 /404.html;
  #   location = /40x.html {
  #
  #   }
  #
  #   error_page 500 502 503 504 /50x.html;
  #   location = /50x.html {
  #
  #   }
  # }
}

################################################################################
1.卸载Nginx
apt-get remove nginx*

准备工作

mkdir Nginx && cd ~/Nginx/

Nginx官网

  1. 下载
    git clone git@github.com:nginx/nginx.git
  2. 配置
    ./configure --help

###############################################################################

sudo apt-get -y install autoconf automake build-essential libass-dev libgpac-dev libsdl1.2-dev libtheora-dev libtool libvdpau-dev libvorbis-dev libx11-dev libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev libssl-dev

编译环境gcc g++ 开发库之类

ubuntu/debian:

sudo apt-get install build-essential
sudo apt-get install libtool

centos/redhat:

安装make:
yum -y install gcc automake autoconf libtool make
安装g++:
yum install gcc gcc-c++

添加依赖: install zlib zlib-devel openssl openssl-devel pcre-devel

zlib:nginx提供gzip模块,需要zlib库支持
openssl:nginx提供ssl功能
pcre:支持地址重写rewrite功能

1.pcre 需要安装libpcre

--with-pcre=/usr/local/src/pcre-8.34

ubuntu/debian:
sudo apt-get install libpcre3 libpcre3-dev

centos/redhat:
yum install pcre-devel

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
tar -zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure
make
make install

2.SSL modules require the OpenSSL library

--with-http_ssl_module
--with-openssl=/usr/local/src/openssl-1.0.1c

ubuntu/debian:
sudo apt-get install openssl
sudo apt-get install libssl-dev

centos/redhat:
yum -y install openssl openssl-devel

wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz

3.zlib

--with-zlib=/usr/local/src/zlib-1.2.8
安装zlib库
http://zlib.net/zlib-1.2.8.tar.gz 下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包:
cd /usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
################################################################################

模块:

编译安装ffmpeg及其依赖包

https://trac.ffmpeg.org/
git clone git@github.com:FFmpeg/FFmpeg.git
cd ffmpeg
#./configure
--prefix=/opt/ffmpeg/
--enable-version3
--enable-libvpx
--enable-libfaac
--enable-libmp3lame
--enable-libvorbis
--enable-libx264
--enable-libxvid
--enable-shared
--enable-gpl
--enable-postproc
--enable-nonfree
--enable-avfilter
--enable-pthreads
--prefix=/usr --extra-version=0ubuntu0.15.10.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --enable-shared --disable-stripping --enable-avresample --enable-avisynth --enable-frei0r --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-openal --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libxvid --enable-libzvbi --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-libssh --enable-libsoxr --enable-libx264 --enable-libopencv --enable-libx265
#make && make install
vim objs/Makefile (修改objs/Makefile文件, 去掉其中的"-Werror"), 然后就能够正常编译了.

nginx-rtmp-module
git clone git@github.com:arut/nginx-rtmp-module.git
./configure --add-module=/path/to/nginx-rtmp-module
./configure --add-module=/path/to/nginx-rtmp-module --with-http_ssl_module
./configure --add-module=/path/to-nginx/rtmp-module --with-debug

#编译错误
./nginx-rtmp-module/ngx_rtmp_core_module.c

@@ -557,7 +557,11 @@ ngx_rtmp_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
             break;
         }

+#if (nginx_version >= 1011000)
+        if (ngx_memcmp(ls[i].sockaddr + off, &u.sockaddr + off, len) != 0) {
+#else
         if (ngx_memcmp(ls[i].sockaddr + off, u.sockaddr + off, len) != 0) {
+#endif
             continue;
         }

@@ -577,7 +581,11 @@ ngx_rtmp_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

     ngx_memzero(ls, sizeof(ngx_rtmp_listen_t));

+#if (nginx_version >= 1011000)
+    ngx_memcpy(ls->sockaddr, &u.sockaddr, u.socklen);
+#else
     ngx_memcpy(ls->sockaddr, u.sockaddr, u.socklen);
+#endif

     ls->socklen = u.socklen;
     ls->wildcard = u.wildcard;

nginx_mod_h264_streaming(支持h264编码的视频)
wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz

git clone git@github.com:vivus-ignis/nginx_mod_h264_streaming.git

./configure --add-module=$HOME/nginx_mod_h264_streaming --sbin-path=/usr/local/sbin --with-debug

  1. 将 ./nginx_mod_h264_streaming/src/ngx_http_streaming_module.c 文件中以下代码删除或者是注释掉就可以了:

    /* TODO: Win32 */
    
    // if (r->zero_in_uri)
    // {
    //    return NGX_DECLINED;
    // }
    

################################################################################
cp auto/configure .
#配置nginx
./configure
--prefix=/usr/local/nginx
--with-http_flv_module
--with-http_mp4_module
--with-http_ssl_module
--with-http_gzip_static_module
--with-http_stub_status_module
--with-pcre
--user=nginx
--group=nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--add-module=../nginx-rtmp-module
--add-module=../nginx_mod_h264_streaming
#--with-cc-opt=-I/opt/ffmpeg/include
--with-ld-opt=’-L/opt/ffmpeg/lib -Wl,-rpath=/opt/ffmpeg/lib’

#--pid-path=/usr/local/nginx/logs/nginx.pid
#--error-log-path=/usr/local/nginx/logs/error.log
#--http-log-path=/usr/local/nginx/logs/access.log
##编译错误解决

  1. mp4_reader.

    # vim objs/Makefile (修改objs/Makefile文件, 去掉其中的"-Werror"), 然后就能够正常编译了.
    

make -j4 && sudo make install
##
make -f objs/Makefile install

 mv '/usr/sbin/nginx' '/usr/sbin/nginx.old'
cp objs/nginx '/usr/sbin/nginx'

mkdir -p '/etc/nginx'
cp conf/mime.types '/etc/nginx/mime.types.default'
cp conf/nginx.conf '/etc/nginx/nginx.conf'
cp conf/nginx.conf '/etc/nginx/nginx.conf.default'

mkdir -p '/usr/local/nginx/logs'
cp -R docs/html '/usr/local/nginx'

##添加类型支持
vim /usr/local/nginx/conf/mime.types

application/vnd.apple.mpegurl m3u8;
application/x-mpegURL                 m3u8;

video/MP2T                             ts;

###################################################
sudo vim /etc/nginx/nginx.conf
+ include /etc/nginx/conf.d/*.conf;

1.建立nginx
sudo groupadd -r nginx
sudo useradd -s /sbin/nologin -g nginx -r nginx
id nginx 

2.验证配置文件
sudo nginx -t
sudo nginx -t -c /usr/local/nginx/conf/nginx.conf

3.启动nginx
sudo nginx
ps -ef | grep nginx

4.更改配置重启nginx  
nginx -s reload
kill -HUP 主进程号或进程号文件路径

5.查询nginx主进程号
  ps -ef | grep nginx
  从容停止 kill -QUIT 主进程号
  快速停止 kill -TERM 主进程号
  强制停止 kill -9 nginx
  若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
  kill -信号类型 '/usr/local/nginx/logs/nginx.pid'

403解决办法:chown -R nginx:nginx /htdocs

  1. 添加 crossdomain.xml 解决m3u8播放问题
    sudo cp ./EasyDarwin/EasyDarwin/WinNTSupport/Movies/crossdomain.xml /usr/local/nginx/html/

###################################################
cp auto/configure .

centos 默认配置

--prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--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-http_ssl_module
--with-http_realip_module
--with-http_addition_module
--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_random_index_module
--with-http_secure_link_module
--with-http_stub_status_module
--with-http_auth_request_module
--with-mail
--with-mail_ssl_module
--with-file-aio
--with-ipv6
--with-http_spdy_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'

configure arguments: ubuntu 16
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2'
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now'
--prefix=/usr/share/nginx
--conf-path=/etc/nginx/nginx.conf
--http-log-path=/var/log/nginx/access.log
--error-log-path=/var/log/nginx/error.log
--lock-path=/var/lock/nginx.lock
--pid-path=/run/nginx.pid
--http-client-body-temp-path=/var/lib/nginx/body
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-proxy-temp-path=/var/lib/nginx/proxy
--http-scgi-temp-path=/var/lib/nginx/scgi
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi
--with-debug
--with-pcre-jit
--with-ipv6
--with-http_ssl_module
--with-http_stub_status_module
--with-http_realip_module
--with-http_auth_request_module
--with-http_addition_module
--with-http_dav_module
--with-http_geoip_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_image_filter_module
--with-http_v2_module
--with-http_sub_module
--with-http_xslt_module
--with-stream
--with-stream_ssl_module
--with-mail
--with-mail_ssl_module
--with-threads

////////////////////////////////////////////////////////////////////
Nginx编译参数详细介绍
--prefix= 指向安装目录
--sbin-path 指向(执行)程序文件(nginx)
--conf-path= 指向配置文件(nginx.conf)
--error-log-path= 指向错误日志目录
--pid-path= 指向pid文件(nginx.pid)
--lock-path= 指向lock文件(nginx.lock)(安装文件锁定,防止安装文件被别人利用,或自己误操作。)
--user= 指定程序运行时的非特权用户
--group= 指定程序运行时的非特权用户组
--builddir= 指向编译目录
--with-rtsig_module 启用rtsig模块支持(实时信号)
--with-select_module 启用select模块支持(一种轮询模式,不推荐在高载环境下使用)禁用:--without-select_module
--with-poll_module 启用poll模块支持(功能与select相同,与select特性相同,为一种轮询模式,不推荐在高载环境下使用)
--with-file-aio 启用file aio支持(一种APL文件传输格式)
--with-ipv6 启用ipv6支持
--with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
--with-http_realip_module 启用ngx_http_realip_module支持(这个模块允许从请求标头更改客户端的IP地址值,默认为关)
--with-http_addition_module 启用ngx_http_addition_module支持(作为一个输出过滤器,支持不完全缓冲,分部分响应请求)
--with-http_xslt_module 启用ngx_http_xslt_module支持(过滤转换XML请求)
--with-http_image_filter_module 启用ngx_http_image_filter_module支持(传输JPEG/GIF/PNG 图片的一个过滤器)(默认为不启用。gd库要用到)
--with-http_geoip_module 启用ngx_http_geoip_module支持(该模块创建基于与MaxMind GeoIP二进制文件相配的客户端IP地址的ngx_http_geoip_module变量)
--with-http_sub_module 启用ngx_http_sub_module支持(允许用一些其他文本替换nginx响应中的一些文本)
--with-http_dav_module 启用ngx_http_dav_module支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)默认情况下为关闭,需编译开启
--with-http_flv_module 启用ngx_http_flv_module支持(提供寻求内存使用基于时间的偏移量文件)
--with-http_gzip_static_module 启用ngx_http_gzip_static_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支持(允许在内存不足的情况下返回204或444码)
--with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
--without-http_charset_module 禁用ngx_http_charset_module支持(重新编码web页面,但只能是一个方向--服务器端到客户端,并且只有一个字节的编码可以被重新编码)
--without-http_gzip_module 禁用ngx_http_gzip_module支持(该模块同-with-http_gzip_static_module功能一样)
--without-http_ssi_module 禁用ngx_http_ssi_module支持(该模块提供了一个在输入端处理处理服务器包含文件(SSI)的过滤器,目前支持SSI命令的列表是不完整的)
--without-http_userid_module 禁用ngx_http_userid_module支持(该模块用来处理用来确定客户端后续请求的cookies)
--without-http_access_module 禁用ngx_http_access_module支持(该模块提供了一个简单的基于主机的访问控制。允许/拒绝基于ip地址)
--without-http_auth_basic_module禁用ngx_http_auth_basic_module(该模块是可以使用用户名和密码基于http基本认证方法来保护你的站点或其部分内容)
--without-http_autoindex_module 禁用disable 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支持(该模块用来基于某些条件划分用户。条件如:ip地址、报头、cookies等等)
--without-http_referer_module 禁用disable ngx_http_referer_module支持(该模块用来过滤请求,拒绝报头中Referer值不正确的请求)
--without-http_rewrite_module 禁用ngx_http_rewrite_module支持(该模块允许使用正则表达式改变URI,并且根据变量来转向以及选择配置。如果在server级别设置该选项,那么他们将在 location之前生效。如果在location还有更进一步的重写规则,location部分的规则依然会被执行。如果这个URI重写是因为location部分的规则造成的,那么 location部分会再次被执行作为新的URI。 这个循环会执行10次,然后Nginx会返回一个500错误。)
--without-http_proxy_module 禁用ngx_http_proxy_module支持(有关代理服务器)
--without-http_fastcgi_module 禁用ngx_http_fastcgi_module支持(该模块允许Nginx 与FastCGI 进程交互,并通过传递参数来控制FastCGI 进程工作。 )FastCGI一个常驻型的公共网关接口。
--without-http_uwsgi_module 禁用ngx_http_uwsgi_module支持(该模块用来医用uwsgi协议,uWSGI服务器相关)
--without-http_scgi_module 禁用ngx_http_scgi_module支持(该模块用来启用SCGI协议支持,SCGI协议是CGI协议的替代。它是一种应用程序与HTTP服务接口标准。它有些像FastCGI但他的设计 更容易实现。)
--without-http_memcached_module 禁用ngx_http_memcached_module支持(该模块用来提供简单的缓存,以提高系统效率)
-without-http_limit_zone_module 禁用ngx_http_limit_zone_module支持(该模块可以针对条件,进行会话的并发连接数控制)
--without-http_limit_req_module 禁用ngx_http_limit_req_module支持(该模块允许你对于一个地址进行请求数量的限制用一个给定的session或一个特定的事件)
--without-http_empty_gif_module 禁用ngx_http_empty_gif_module支持(该模块在内存中常驻了一个1*1的透明GIF图像,可以被非常快速的调用)
--without-http_browser_module 禁用ngx_http_browser_module支持(该模块用来创建依赖于请求报头的值。如果浏览器为modern ,则$modern_browser等于modern_browser_value指令分配的值;如 果浏览器为old,则$ancient_browser等于 ancient_browser_value指令分配的值;如果浏览器为 MSIE中的任意版本,则 $msie等于1)
--without-http_upstream_ip_hash_module 禁用ngx_http_upstream_ip_hash_module支持(该模块用于简单的负载均衡)
--with-http_perl_module 启用ngx_http_perl_module支持(该模块使nginx可以直接使用perl或通过ssi调用perl)
--with-perl_modules_path= 设定perl模块路径
--with-perl= 设定perl库文件路径
--http-log-path= 设定access log路径
--http-client-body-temp-path= 设定http客户端请求临时文件路径
--http-proxy-temp-path= 设定http代理临时文件路径
--http-fastcgi-temp-path= 设定http fastcgi临时文件路径
--http-uwsgi-temp-path= 设定http uwsgi临时文件路径
--http-scgi-temp-path= 设定http scgi临时文件路径
-without-http 禁用http server功能
--without-http-cache 禁用http cache功能
--with-mail 启用POP3/IMAP4/SMTP代理模块支持
--with-mail_ssl_module 启用ngx_mail_ssl_module支持
--without-mail_pop3_module 禁用pop3协议(POP3即邮局协议的第3个版本,它是规定个人计算机如何连接到互联网上的邮件服务器进行收发邮件的协议。是因特网电子邮件的第一个离线协议标 准,POP3协议允许用户从服务器上把邮件存储到本地主机上,同时根据客户端的操作删除或保存在邮件服务器上的邮件。POP3协议是TCP/IP协议族中的一员,主要用于 支持使用客户端远程管理在服务器上的电子邮件)
--without-mail_imap_module 禁用imap协议(一种邮件获取协议。它的主要作用是邮件客户端可以通过这种协议从邮件服务器上获取邮件的信息,下载邮件等。IMAP协议运行在TCP/IP协议之上, 使用的端口是143。它与POP3协议的主要区别是用户可以不用把所有的邮件全部下载,可以通过客户端直接对服务器上的邮件进行操作。)
--without-mail_smtp_module 禁用smtp协议(SMTP即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式。SMTP协议属于TCP/IP协议族,它帮助每台计算机在发送或中转信件时找到下一个目的地。)
--with-google_perftools_module 启用ngx_google_perftools_module支持(调试用,剖析程序性能瓶颈)
--with-cpp_test_module 启用ngx_cpp_test_module支持
--add-module= 启用外部模块支持
--with-cc= 指向C编译器路径
--with-cpp= 指向C预处理路径
--with-cc-opt= 设置C编译器参数(PCRE库,需要指定--with-cc-opt=”-I /usr/local/include”,如果使用select()函数则需要同时增加文件描述符数量,可以通过--with-cc- opt=”-D FD_SETSIZE=2048”指定。)
--with-ld-opt= 设置连接文件参数。(PCRE库,需要指定--with-ld-opt=”-L /usr/local/lib”。)
--with-cpu-opt= 指定编译的CPU,可用的值为: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
--without-pcre 禁用pcre库
--with-pcre 启用pcre库
--with-pcre= 指向pcre库文件目录
--with-pcre-opt= 在编译时为pcre库设置附加参数
--with-md5= 指向md5库文件目录(消息摘要算法第五版,用以提供消息的完整性保护)
--with-md5-opt= 在编译时为md5库设置附加参数
--with-md5-asm 使用md5汇编源
--with-sha1= 指向sha1库目录(数字签名算法,主要用于数字签名)
--with-sha1-opt= 在编译时为sha1库设置附加参数
--with-sha1-asm 使用sha1汇编源
--with-zlib= 指向zlib库目录
--with-zlib-opt= 在编译时为zlib设置附加参数
--with-zlib-asm= 为指定的CPU使用zlib汇编源进行优化,CPU类型为pentium, pentiumpro
--with-libatomic 为原子内存的更新操作的实现提供一个架构
--with-libatomic= 指向libatomic_ops安装目录
--with-openssl= 指向openssl安装目录
--with-openssl-opt 在编译时为openssl设置附加参数
--with-debug 启用debug日志

`