admin 管理员组文章数量: 887044
2024年1月4日发(作者:苹果手机split使用教程)
Nginx 中文官方文档主要文档Nginx功能概述Nginx功能概述HTTP基础功能:处理静态文件,索引文件以及自动索引;反向代理加速(无缓存),简单的负载均衡和容错;FastCGI,简单的负载均衡和容错;模块化的结构。过滤器包括gzipping, byte ranges, chunked responses, 以及 SSI-filter 。在SSI过滤器中,到同一个 proxy 或者 FastCGI 的多个子请求并发处理;SSL 和 TLS SNI 支持;IMAP/POP3 代理服务功能:使用外部 HTTP 认证服务器重定向用户到 IMAP/POP3 后端;使用外部 HTTP 认证服务器认证用户后连接重定向到内部的 SMTP 后端;认证方法:POP3: POP3 USER/PASS, APOP, AUTH LOGIN PLAIN CRAM-MD5;IMAP: IMAP LOGIN;SMTP: AUTH LOGIN PLAIN CRAM-MD5;SSL 支持;在 IMAP 和 POP3 模式下的 STARTTLS 和 STLS 支持;支持的操作系统:FreeBSD 3.x, 4.x, 5.x, 6.x i386; FreeBSD 5.x, 6.x amd64;Linux 2.2, 2.4, 2.6 i386; Linux 2.6 amd64;Solaris 8 i386; Solaris 9 i386 and sun4u; Solaris 10 i386;MacOS X (10.4) PPC;结构与扩展:一个主进程和多个工作进程。工作进程是单线程的,且不需要特殊授权即可运行;kqueue (FreeBSD 4.1+), epoll (Linux 2.6+), rt signals (Linux 2.2.19+), /dev/poll (Solaris 711/99+), select, 以及 poll 支持;kqueue支持的不同功能包括 EV_CLEAR, EV_DISABLE (临时禁止事件), NOTE_LOWAT, EV_EOF,本文档使用 看云 构建- 1 -
Nginx 中文官方文档有效数据的数目,错误代码;sendfile (FreeBSD 3.1+), sendfile (Linux 2.2+), sendfile64 (Linux 2.4.21+), 和 sendfilev (Solaris 87/01+) 支持;输入过滤 (FreeBSD 4.1+) 以及 TCP_DEFER_ACCEPT (Linux 2.4+) 支持;10,000 非活动的 HTTP keep-alive 连接仅需要 2.5M 内存。最小化的数据拷贝操作;其他HTTP功能:基于IP 和名称的虚拟主机服务;Memcached 的 GET 接口;支持 keep-alive 和管道连接;灵活简单的配置;重新配置和在线升级而无须中断客户的工作进程;可定制的访问日志,日志写入缓存,以及快捷的日志回卷;4xx-5xx 错误代码重定向;基于 PCRE 的 rewrite 重写模块;基于客户端 IP 地址和 HTTP 基本认证的访问控制;PUT, DELETE, 和 MKCOL 方法;支持 FLV (Flash 视频);带宽限制;实验特性:内嵌的 perl通过 aio_read() / aio_write() 的套接字工作的实验模块,仅在 FreeBSD 下。对线程的实验化支持,FreeBSD 4.x 的实现基于 rfork()Nginx 主要的英语站点是 /en/英语文档草稿由 Aleksandar Lazic 完成 点击 。为什么选择Nginx为什么选择NginxNginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性:作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤其受到虚拟主机提供商的欢迎。能够支持高达 50,000 个并发连接数的响应,感谢 Nginx为我们选择了 epoll and kqueue 作为开发模型.本文档使用 看云 构建- 2 -
Nginx 中文官方文档作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器 对作为负载均衡服务器外进行服务。Nginx 用 C 编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也作为邮件代理服务器是作为邮件代理服务器), 描述了成功并且美妙的使用经验。Nginx 安装非常的简单,配置文件 非常简洁(还能够支持perl语法),Bugs非常少的服务器: Nginx 启动Nginx 安装非常的简单,配置文件 非常简洁(还能够支持perl语法),Bugs非常少的服务器特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在 不间断服务的情况下进行软件版本的升级。Nginx安装Nginx安装nginx可以使用各平台的默认包来安装,本文是介绍使用源码编译安装,包括具体的编译参数信息。正式开始前,编译环境gcc g++ 开发库之类的需要提前装好,这里默认你已经装好。ububtu平台编译环境可以使用以下指令apt-get install build-essentialapt-get install libtoolcentos平台编译环境使用如下指令安装make:yum -y install gcc automake autoconf libtool make安装g++:yum install gcc gcc-c++下面正式开始一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。
1.选定源码目录 1.选定源码目录可以是任何目录,本文选定的是/usr/local/srccd /usr/local/src本文档使用 看云 构建- 3 -
Nginx 中文官方文档2.安装PCRE库 2.安装PCRE库ftp:///pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:cd /usr/local/srcwget ftp:///pub/software/programming/pcre/
tar -zxvf pcre-8.34./configuremakemake install3.安装zlib库 3.安装zlib库/ 下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包:cd /usr/local/srcwget / -zxvf zlib-1.2.8./configuremakemake install4.安装ssl(某些vps默认没装ssl)cd /usr/local/srcwget /source/ -zxvf 5.安装nginxNginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:本文档使用 看云 构建- 4 -
Nginx 中文官方文档cd /usr/local/srcwget /download/ -zxvf nginx-1.4.2./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/ --pid-path=/usr/local/nginx/ --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.34 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1cmakemake install--with-pcre=/usr/src/pcre-8.34 指的是pcre-8.34 的源码路径。
--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源码路径。安装成功后 /usr/local/nginx 目录下如下 koi-win t logs scgi_paramsfastcgi_params scgi_tfastcgi_t t uwsgi_paramshtml nginx uwsgi_tkoi-utf win-utf6.启动
确保系统的 80 端口没被其他程序占用,运行/usr/local/nginx/nginx 命令来启动 Nginx,netstat -ano|grep 80如果查不到结果后执行,有结果则忽略此步骤(ubuntu下必须用sudo启动,不然只能在前台运行)sudo /usr/local/nginx/nginx打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。到这里nginx就安装完成了,如果只是处理静态html就不用继续安装了如果你需要处理php脚本的话,还需要安装php-fpm。本文档使用 看云 构建- 5 -
Nginx 中文官方文档下面安装排错附:可能遇到的错误和一些帮助信息1.1编译pcre错误libtool: compile: unrecognized option `-DHAVE_CONFIG_H'libtool: compile: Try `libtool --help' for more [1]: *** [] Error 1make[1]: Leaving directory `/usr/local/src/pcre-8.34'make: *** [all] Error 2解决办法:安装g++,别忘了重新configureapt-get install g++apt-get install build-essentialmake clean./configuremake1.2 make出错make: *** No rule to make target `build', needed by `default'. Stop../configure: error: SSL modules require the OpenSSL can either do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using --with-openssl=本文档使用 看云 构建- 6 -
Nginx 中文官方文档本文档使用 看云 构建- 7 -
Nginx 中文官方文档option.
按照第4步的安装方法或
ubuntu下apt-get install opensslapt-get install libssl-devcentos下yum -y install openssl 编译选项make是用来编译的,它从Makefile中读取指令,然后编译。本文档使用 看云 构建- 8 -
Nginx 中文官方文档make install是用来安装的,它也从Makefile中读取指令,安装到指定的位置。configure命令是用来检测你的安装平台的目标特征的。它定义了系统的各个方面,包括nginx的被允许使用的连接处理的方法,比如它会检测你是不是有CC或GCC,并不是需要CC或GCC,它是个shell脚本,执行结束时,它会创建一个Makefile文件。nginx的configure命令支持以下参数:--prefix=path 定义一个目录,存放服务器上的文件 ,也就是nginx的安装目录。默认使用
/usr/local/nginx。--sbin-path=path 设置nginx的可执行文件的路径,默认为 `*prefix*/sbin/nginx`.--conf-path=path 设置在配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为`*prefix*/conf/`.--pid-path=path 设置文件,将存储的主进程的进程号。安装完成后,可以随时改变的文件名 , 在配置文件中使用 PID指令。默认情况下,文件名 为`*prefix*/logs/`.--error-log-path=path 设置主错误,警告,和诊断文件的名称。安装完成后,可以随时改变的文件名 ,在配置文件中 使用 的error_log指令。默认情况下,文件名 为`*prefix*/logs/`.--http-log-path=path 设置主请求的HTTP服务器的日志文件的名称。安装完成后,可以随时改变的文件名 ,在配置文件中 使用 的access_log指令。默认情况下,文件名 为`*prefix*/logs/`.--user=name 设置nginx工作进程的用户。安装完成后,可以随时更改的名称在配置文件中 使用的 user指令。默认的用户名是nobody。--group=name 设置nginx工作进程的用户组。安装完成后,可以随时更改的名称在配置文件中 使用的 user指令。默认的为非特权用户。--with-select_module``--without-select_module 启用或禁用构建一个模块来允许服务器使用select()方法--with-poll_module``--without-poll_module 启用或禁用构建一个模块来允许服务器使用poll()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。--without-http_gzip_module — 不编译压缩的HTTP服务器的响应模块。编译并运行此模块需要zlib库。--without-http_rewrite_module 不编译重写模块。编译并运行此模块需要PCRE库支持。--without-http_proxy_module — 不编译http_proxy模块。--with-http_ssl_module — 使用https协议模块。默认情况下,该模块没有被构建。建立并运行此模块的OpenSSL库是必需的。--with-pcre=path — 设置PCRE库的源码路径。PCRE库的源码(版本4.4 - 8.30)需要从PCRE网站下载并解压。其余的工作是Nginx的./ configure和make来完成。正则表达式使用在location指令和ngx_http_rewrite_module 模块中。--with-pcre-jit —编译PCRE包含“just-in-time compilation”(1.1.12中, pcre_jit指令)。--with-zlib=path —设置的zlib库的源码路径。要下载从 zlib(版本1.1.3 - 1.2.5)的并解压。其余本文档使用 看云 构建- 9 -
Nginx 中文官方文档的工作是Nginx的./ configure和make完成。ngx_http_gzip_module模块需要使用zlib 。--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".典型实例(下面为了展示需要写在多行,执行时内容需要在同一行)./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/ --pid-path=/usr/local/nginx/ --with-http_ssl_module --with-pcre=../pcre-4.4 --with-zlib=../zlib-1.1.3运行和控制Nginx运行和控制Nginxnginx命令行参数不像许多其他软件系统,Nginx 仅有几个命令行参数,完全通过配置文件来配置-c 为 Nginx 指定一个配置文件,来代替缺省的。为 Nginx 指定一个配置文件,来代替缺省的。-t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用-t到的文件。-v 显示 nginx 的版本。-v-V 显示 nginx 的版本,编译器版本和配置参数。-Vnginx控制信号可以使用信号系统来控制主进程。默认,nginx 将其主进程的 pid 写入到 /usr/local/nginx/ 文件中。通过传递参数给 ./configure 或使用 pidpid 指令,来改变该文件的位置。主进程可以处理以下的信号:TERM, INTQUIT快速关闭从容关闭- 10 -本文档使用 看云 构建
Nginx 中文官方文档重载配置HUP用新的配置开始新的工作进程从容关闭旧的工作进程USR1USR2WINCH重新打开日志文件平滑升级可执行程序。从容关闭工作进程尽管你不必自己操作工作进程,但是,它们也支持一些信号:TERM, INTQUITUSR1快速关闭从容关闭重新打开日志文件nginx 启动、停止、重启命令nginx启动sudo /usr/local/nginx/nginx (nginx二进制文件绝对路径,可以根据自己安装路径实际决定)nginx从容停止命令,等所有请求结束后关闭服务ps -ef |grep nginxkill -QUIT nginx主进程号nginx 快速停止命令,立刻关闭nginx进程ps -ef |grep nginxkill -TERM nginx主进程号如果以上命令不管用,可以强制停止kill -9 nginx主进程号如果嫌麻烦可以不用查看进程号,直接使用命令进行操作
其中/usr/local/nginx/ 为中pid命令设置的参数,用来存放nginx主进程号的文件
kill -信号类型(HUP|TERM|QUIT) cat /usr/local/nginx/
例如kill -QUIT `cat /usr/local/nginx/`nginx重启命令nginx重启可以分成几种类型本文档使用 看云 构建- 11 -
Nginx 中文官方文档1.简单型,先关闭进程,修改你的配置后,重启进程。
kill -QUIT cat /usr/local/nginx/
sudo /usr/local/nginx/nginx
2.重新加载配置文件,不重启进程,不会停止处理请求
3.平滑更新nginx二进制,不会停止处理请求使用信号加载新的配置Nginx 支持几个信号,能在它运行时控制其操作。其中最普通的是 15 ,用来中止运行的进程:# ps aux | egrep '(PID|nginx)'USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 2213 0.0 0.0 6784 2036 ? Ss 03:01 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/# kill -15 2213而最有趣的是能平滑改变 nginx 配置的选项(请注意,在重载前,要先测试一下配置文件):# nginx -t -c /etc/nginx/2006/09/16 13:07:10 [info] 15686#0: the configuration file /etc/nginx/ syntax is ok2006/09/16 13:07:10 [info] 15686#0: the configuration file /etc/nginx/ was tested successfully# ps aux | egrep '(PID|nginx)'USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 2213 0.0 0.0 6784 2036 ? Ss 03:01 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/# kill -HUP 2213当 nginx 接收到 HUP 信号,它会尝试先解析配置文件(如果指定配置文件,就使用指定的,否则使用默认的),成功的话,就应用新的配置文件(例如:重新打开日志文件或监听的套接 字)。之后,nginx 运行新的工作进程并从容关闭旧的工作进程。通知工作进程关闭监听套接字但是继续为当前连接的客户提供服务。所有客户端的服务完成后,旧的工作进程被关闭。 如果新的配置文件应用失败,nginx 将继续使用旧的配置进行工作。平滑升级到新的二进制代码你可以在不中断服务的情况下 - 新的请求也不会丢失,使用新的 nginx 可执行程序替换旧的(当升级新版本或添加/删除服务器模块时)。首先,使用新的可执行程序替换旧的(最好做好备份),然后,发送 USR2 (kill -USR2 pid)信号给主进程。主进程将重命名它的 . 文件为 . (比如:/usr/local/nginx/logs//usr/local/nginx/logs/),然后执行新的可执行程序,依次启动新的主进程和新的工作进程:本文档使用 看云 构建- 12 -
Nginx 中文官方文档 PID PPID USER %CPU VSZ WCHAN COMMAND33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx33134 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)33135 33126 nobody 0.0 1380 kqread nginx: worker process (nginx)33136 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)36264 33126 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx36265 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)36266 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)36267 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)在这时,两个 nginx 实例会同时运行,一起处理输入的请求。要逐步停止旧的实例,你必须发送 WINCH信号给旧的主进程,然后,它的工作进程就将开始从容关闭: PID PPID USER %CPU VSZ WCHAN COMMAND33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx33135 33126 nobody 0.0 1380 kqread nginx: worker process is shutting down (nginx)36264 33126 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx36265 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)36266 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)36267 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)一段时间后,旧的工作进程处理了所有已连接的请求后退出,就仅由新的工作进程来处理输入的请求了: PID PPID USER %CPU VSZ WCHAN COMMAND33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx36264 33126 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx36265 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)36266 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)36267 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)这时,因为旧的服务器还尚未关闭它监听的套接字,所以,通过下面的几步,你仍可以恢复旧的服务器:发送 HUP 信号给旧的主进程 - 它将在不重载配置文件的情况下启动它的工作进程发送 QUIT 信号给新的主进程,要求其从容关闭其工作进程发送 TERM 信号给新的主进程,迫使其退出如果因为某些原因新的工作进程不能退出,向其发送 KILL 信号新的主进程退出后,旧的主进程会由移除 . 前缀,恢复为它的 . 文件,这样,一切就都恢复到升级之前了。如果尝试升级成功,而你也希望保留新的服务器时,发送 QUIT 信号给旧的主进程使其退出而只留下新的服务器运行:本文档使用 看云 构建- 13 -
Nginx 中文官方文档 PID PPID USER %CPU VSZ WCHAN COMMAND 36264 1 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx 36265 36264 nobody 0.0 1364 kqread nginx: worker process (nginx) 36266 36264 nobody 0.0 1364 kqread nginx: worker process (nginx) 36267 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)配置符号参考配置符号参考容量符号缩写k,Km,M千字节兆字节例如, "8k", "1m" 代表字节数计量.时间符号缩写mssmhdwMy毫秒秒分钟小时日周一个月, 30天年, 365 天例如, "1h 30m", "1y 6M". 代表 "1小时 30分", "1年零6个月".优化 Nginx优化 NginxNgnix使用hash表来协助完成请求的快速处理。考虑到保存键及其值的hash表存储单元的大小不至于超出设定参数(hash bucket size), 在启动和每次重本文档使用 看云 构建- 14 -
Nginx 中文官方文档新配置时,Nginx为hash表选择尽可能小的尺寸。直到hash表超过参数(hash max size)的大小才重新进行选择. 对于大多数hash表都有指令来修改这些参数。例如,保存服务器名字的hash表是由指令 server_names_hash_max_size 和
server_names_hash_bucket_size所控制的。参数hash bucket size总是等于hash表的大小,并且是一路处理器缓存大小的倍数。在减少了在内存中的存取次数后,使在处理器中加速查找hash表键值成为可能。如果hash bucket size等于一路处理器缓存的大小,那么在查找键的时候,最坏的情况下在内存中查找的次数为2。第一次是确定存储单元的地址,第二次是在存储单元中查找键值。因此,如果Nginx给出需要增大 hash max size 或 hash bucket size的提示,那么首要的是增大前一个参数的大小.事件模型Nginx支持如下处理连接的方法(I/O复用方法),这些方法可以通过use指令指定。select - 标准方法。 如果当前平台没有更有效的方法,它是编译时默认的方法。你可以使用配置参数 select--with-select_module 和 --without-select_module 来启用或禁用这个模块。poll - 标准方法。 如果当前平台没有更有效的方法,它是编译时默认的方法。你可以使用配置参数 poll--with-poll_module 和 --without-poll_module 来启用或禁用这个模块。kqueue - 高效的方法,使用于 FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X. 使用双处kqueue理器的MacOS X系统使用kqueue可能会造成内核崩溃。epoll - 高效的方法,使用于Linux内核2.6版本及以后的系统。在某些发行版本中,如SuSE 8.2, 有让epoll2.4版本的内核支持epoll的补丁。rtsig - 可执行的实时信号,使用于Linux内核版本2.2.19以后的系统。默认情况下整个系统中不能出现rtsig大于1024个POSIX实时(排队)信号。这种情况对于高负载的服务器来说是低效的;所以有必要通过调节内核参数 /proc/sys/kernel/rtsig-max 来增加队列的大小。可是从Linux内核版本2.6.6-mm2开始,这个参数就不再使用了,并且对于每个进程有一个独立的信号队列,这个队列的大小可以用RLIMIT_SIGPENDING 参数调节。当这个队列过于拥塞,nginx就放弃它并且开始使用 poll 方法来处理连接直到恢复正常。/dev/poll - 高效的方法,使用于 Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和/dev/pollTru64 UNIX 5.1A+.eventport - 高效的方法,使用于 Solaris 10. 为了防止出现内核崩溃的问题, 有必要安装 eventport这个 安全补丁。参考Hash表原始文档常见问题(FAQ)常见问题(FAQ)本文档使用 看云 构建- 15 -
Nginx 中文官方文档[#notwork 某些东东不工作 (URL重写, 代理, 路径, ...)][#other 有没有其它类似的Web服务器][#chroot 对于chroot的支持是否在计划之中?][#usecase 在什么情况下使用Nginx比使用squid要好?][#imapexample 有没有人能给出一个完整的.conf配置文件来详细的解读一下怎么配置和测试 IMAP模块, 而不只是关于 IMAP 的只言片语啊?][#smtpexample 怎么让Nginx成为以postfix做为后端的SMTP代理?][#loadbalancing Nginx使用什么算法来实现负载均衡? 它能实现基于连接数的负载均衡吗?][#proxy_buffering 我能关闭从代理服务器到后端服务器的缓存吗或者使用上传进度特性?]某些东东不工作 (URL重写, 代理, 路径, ...)例如: 如URL重写(rewrite)不工作了或者是unix的路径(/$PATH)的问题云云...请仔细阅读 [NginxDebugging] 并且 逐行 查看错误日志。 逐行如果你没找到错误 打起精神打起精神 试着到IRC或邮件列表里说明一下你碰到的问题。有没有其它类似的Web服务器CherokeeLighttpd (Lighty)thttpd关于各自的优缺点请使用自己喜欢的搜索引挚查找 ;-)对于chroot的支持是否在计划之中?有人知道吗?在什么情况下使用Nginx比使用squid要好? 反之亦然。大体上来说nginx主要用于反向加速代理而不是像squid那样做为常规代理服务器。Nginx的最大优势在于高负载情况下内存和CPU的低消耗。 我不认为squid能给你带来比nginx更好的性能。怎么让Nginx成为以postfix做为后端的SMTP代理?有人知道不?Nginx使用什么算法来实现负载均衡? 它能实现基于连接数的负载均衡吗?目前Nginx使用简单的轮巡算法,所以无法做基本链接计数的负载均衡。 这个可能会在将来的版本中有所改变。本文档使用 看云 构建- 16 -
Nginx 中文官方文档> 我能关闭从代理服务器到后端服务器的缓存吗或者使用上传进度特性?基于 太多太多人询问下面的问题:我能为了得到上传进度而关闭代理的缓存吗使用nginx我怎么才能给用户显示上传进度...到目前为止 (2007-Apr-26) 还没有办法关闭到后端服务器的缓存.调试 nginx调试 nginxNginx的一个 杀手级特性杀手级特性 就是你能使用 debug_connection 指令只调试 某些某些 连接。这个设置只有是你使用
--with-debug 编译的nginx才有效。本文档使用 看云 构建- 17 -
Nginx 中文官方文档核心模块鏍稿績妯″潡Nginx主模块Nginx主模块这里是控制 Nginx 的基本功能的指令.指令[#daemon daemon][#debug_points debug_points][#error_log error_log][#include include][#lock_file lock_file][#master_process master_process][#pid pid][#ssl_engine ssl_engine][#timer_resolution timer_resolution][#user user group][#worker_cpu_affinity worker_cpu_affinity][#worker_priority worker_priority][#worker_processes worker_processes][#worker_rlimit_core worker_rlimit_core][#worker_rlimit_nofile worker_rlimit_nofile][#worker_rlimit_sigpending worker_rlimit_sigpending][#working_directory working_directory]daemon语法:daemon on | off缺省值:ondaemon off;本文档使用 看云 构建- 18 -
Nginx 中文官方文档Do not use the "daemon" and "master_process" directives in a production mode, these optionsare mainly used for development only. You can use daemon off safely in production mode withrunit / daemontools however you can't do a graceful upgrade. master_process off should neverbe used in production.生产环境中不要使用"daemon"和"master_process"指令,这些选项仅用于开发调试。debug_points语法:debug_points [stop | abort]缺省值:nonedebug_points stop;There are some assertion points inside nginx that allow to stop nginx to attach the debugger, orto abort and to create the core file.应该适用于调试,在调试器内设置断点之类的。error_log语法:error_log file [ debug | info | notice | warn | error | crit ]缺省值:${prefix}/logs/nx 添加 --with-debug 编译参数, 你还能够使用以下配置:error_log LOGFILE [ debug_core | debug_alloc | debug_mutex | debug_event]: | debug_http | debug_imap ;include语法:include file | *缺省值:none你可以在任意地方使用include指令实现配置文件的包含,类似于apache中的include方法,可减少主配置文件d。include 指令还支持像下面配置一样的全局包含的方法,例如包含一个目录下所有以".conf"结尾的文件:include vhosts/*.conf;注意路径受到configure编译参数--prefix=<路径>指令的影响,如果没有指定,Nginx默认是被编译本文档使用 看云 构建- 19 -
Nginx 中文官方文档在/usr/local/nginx。语法:lock_file file缺省值:compile-time optionlock_file /var/log/lock_file;nginx uses accept mutex to serialize accept() syscalls. If nginx is built by gcc, Intel C++, or SunProC++ compilers on i386, amd64, sparc64, and ppc64, then nginx uses the atomic instructions toimplement the mutex. In other cases the lock file would be _process语法:master_process on | off缺省值:onmaster_process off;Do not use the "daemon" and "master_process" directives in a production mode, these optionsare mainly used for development only.生产环境中不要使用"daemon"和"master_process"指令,这些选项仅用于开发调试。pid语法:pid file缺省值:compile-time option Example:pid /var/log/;进程id存储文件。可以使用 kill -HUP cat /var/log/ 对Nginx进行配置文件重新加载。ssl_engine语法:ssl_engine engine缺省值:system dependentHere you can set your preferred openssl engine if any available. You can figure out which one doyou have with the commandline tool:该指令用于指定openssl使用的引擎。你可以通过下面的命令行获知系统目前支持的openssl引擎本文档使用 看云 构建- 20 -
Nginx 中文官方文档openssl engine -t例如:$ openssl engine -t(cryptodev) BSD cryptodev engine: [ available ]
(dynamic) Dynamic engine loading support: [ unavailable ]
timer_resolution语法:timer_resolution t缺省值:noneExample:timer_resolution 100ms;The directive allows to decrease number gettimeofday() syscalls. By default gettimeofday() iscalled after each return from kevent(), epoll, /dev/poll, select(), poll().But if you need an exact time in logs when logging $upstream_response_time, or $msecvariables, then you should use timer_语法:user user [group]缺省值:nobody nobody指定Nginx Worker进程运行用户,默认是nobody帐号。例如:user www users;worker_cpu_affinity语法:worker_cpu_affinity cpumask []缺省值:noneLinux this option you can bind the worker process to a CPU, it calls sched_setaffinity().本文档使用 看云 构建- 21 -
Nginx 中文官方文档仅适用于linux,使用该选项可以绑定worker进程和 example,worker_proceses 4;worker_cpu_affinity 0001 0010 0100 1000;Bind each worker process to one CPU only.分别给每个worker进程绑定一个_proceses 2;worker_cpu_affinity 0101 1010;Bind the first worker to CPU0/CPU2, bind the second worker to CPU1/CPU3. This is suitable forHTT.将CPU0/CPU2绑定给第一个worker进程,将CPU1/CPU3绑定给第二个worker进程。worker_priority语法:worker_priority [-] number缺省值:onWith this option you can give to all worker processes the priority (nice) you need/wish, it callssetpriority().使用该选项可以给所有的worker进程分配优先值。worker_processes语法:worker_processes number缺省值:1e.g.:worker_processes 5;nginx has the ability to use more than one worker process for several reasons:nginx可以使用多个worker进程,原因如下:1. to use SMP2. to decrease latency when workers blockend on disk I/O本文档使用 看云 构建- 22 -
Nginx 中文官方文档3. to limit number of connections per process when select()/poll() is usedThe worker_processes and worker_connections from the event sections allows you to calculatemaxclients value: kmax_clients = worker_processes * worker_connectionsworker_rlimit_core语法:worker_rlimit_core size缺省值: '缺省值:Maximum size of core file per worker;worker_rlimit_nofile语法:
worker_rlimit_nofile limit 缺省值: ''Specifies the value for maximum file descriptors that can be opened by this process.指定worker_rlimit_sigpending语法:worker_rlimit_sigpending limit缺省值: '缺省值:(Since Linux 2.6.8) Specifies the limit on the number of signals that may be queued for the realuser ID of the calling g_directory语法:
working_directory path 缺省值:
--prefixThis is the working directory for the workers. It's used for core files only. nginx uses absolutepaths only, all relative paths in configuration files are relative to --prefix==PATHNginx事件模块Nginx事件模块accept_mutexSyntax:accept_mutex [ on | off ]Default:on本文档使用 看云 构建- 23 -
Nginx 中文官方文档nginx 使用连接互斥锁进行顺序的accept()系统调用.accept_mutex_delaySyntax:accept_mutex_delay Nms;Default:500ms如果一个进程没有互斥锁,它将延迟至少多长时间。默认情况下,延迟是500ms 。debug_connectionSyntax:debug_connection [ip | CIDR]Default:noneSince 0.3.54 this option support CIDR address formatThis option gives you the ability to write debug log only for the clients of this IP/l different directives are e:error_log /var/log/nginx/errors;events { debug_connection 192.168.1.1;}devpoll_changesdevpoll_eventskqueue_eventsepoll_eventsSyntax:devpoll_changesDefault:These directives specify how many events may be passed to/from kernel, using default devpoll values are 32, the rest are 512.本文档使用 看云 构建- 24 -
Nginx 中文官方文档multi_acceptSyntax:multi_accept [ on | off ]Default:offmulti_accept tries to accept() as many connections as possible after nginx gets notificationabout a new _signoSyntax:rtsig_signoDefault:nginx uses two signals when the rtsig method is used. The directive specified the first signalnumber. The second is plus default rtsig_signo is SIGRTMIN+10 (40).rtsig_overflow_eventsrtsig_overflow_testrtsig_overflow_thresholdSyntax:rtsig_overflow_*Default:These directives specifies how to handle rtsig queue overflows. When overflow occurred nginxflushes rtsig queue, then it handles events switching between poll() and rtsig. poll() handlesconsecutively all unhandled events, while rtsig periodicaly drains queue to prevent a newoverflow. When overflow is handled completely, nginx switches to rtsig method rtsig_overflow_events specifies the number of events to be passed via poll(). The default rtsig_overflow_test specifies after which number of events handled by poll() nginx will drainsrtsig queue. The default is rtsig_overflow_threshold works in Linux 2.4.x only. Before to drain rtsig queue nginx looks ina kernel how the queue is filled upThe default is 1/10. "rtsig_overflow_threshold 3" means 1/本文档使用 看云 构建- 25 -
Nginx 中文官方文档Syntax:use [ kqueue | rtsig | epoll | /dev/poll | select | poll | eventport ]Default:如果在./configure的时候指定了不止一种事件模型,那么可以设置其中一个,以便告诉nginx使用哪种事件模型。默认情况下nginx会在./configure时找出最适合系统的事件模型。你可以在 这里 查看可用的事件模型以及如何在./configure时激活worker_connectionsSyntax:worker_connections numberDefault:通过worker_connections和worker_proceses可以计算出maxclients:max_clients = worker_processes * worker_connections作为反向代理,max_clients为:max_clients = worker_processes * worker_connections/4Since a browser opens 2 connections by default to a server and nginx uses the fds (filedescriptors) from the same pool to connect to the upstream backendReferences本文档使用 看云 构建- 26 -
Nginx 中文官方文档基本模块鍩烘湰妯″潡http核心模块http核心模块指令aliassyntax:alias file-path|directory-path;default:nocontext:locationThis directive assigns a path to be used for the indicated location. Note that it may look similarto the root directive, but the document root doesn't change, just the file system path used forthe example:location /i/ { alias /spool/w3/images/;}The request "/i/" will return the file "/spool/w3/images/".It is possible to use variables in the replacement alias directive cannot be used inside a regex-specified location. If you need to do this youmust use a combination of rewrite and _body_in_file_onlysyntax:client_body_in_file_only on|offdefault:offcontext:http, server, location本文档使用 看云 构建- 27 -
Nginx 中文官方文档The directive enables to store a client request body in a note that the file at the request completion will not be removed if the directive is directive can be used for debugging and for the $r->request_body_file method in theEmbedded Perl _body_in_single_buffersyntax:client_body_in_single_bufferdefault:offcontext:http, server, locationThe directive(0.7.58+) specifies whether to keep the whole body in a single client request directive is recommended when using the variable $request_body to reduce the operationsof _body_buffer_sizesyntax:client_body_buffer_size the_sizedefault:8k/16kcontext:http, server, locationThe directive specifies the client request body buffer the request body is more than the buffer, then the entire request body or some part is writtenin a temporary default size is equal to two pages size, depending on platform it is either 8K or _body_temp_pathsyntax:client_body_temp_path dir-path [ level1 [ level2 [ level3 ]default:client_body_tempcontext:http, server, locationThe directive assigns the directory for storing the temporary files in it with the body of the dir-path a hierarchy of subdirectories up to three levels are example本文档使用 看云 构建- 28 -
Nginx 中文官方文档client_body_temp_path /spool/nginx/client_temp 1 2;The directory structure will be like this:/spool/nginx/client_temp/7/45/client_body_timeoutsyntax:client_body_timeout timedefault:60context:http, server, locationDirective sets the read timeout for the request body from timeout is set only if a body is not get in one readstep. If after this time the client sendnothing, nginx returns error "Request time out" (408).client_header_buffer_sizesyntax:client_header_buffer_size sizedefault:1kcontext:http, serverDirective sets the headerbuffer size for the request header from the overwhelming majority of requests it is completely sufficient a buffer size of r if a big cookie is in the request-header or the request has come from a wap-client theheader can not be placed in 1K, therefore, the request-header or a line of request-header is notlocated completely in this buffer nginx allocate a bigger buffer, the size of the bigger buffer canbe set with the instruction large_client_header__header_timeoutsyntax:client_header_timeout timedefault:60context:http, serverDirective assigns timeout with reading of the title of the request of timeout is set only if a header is not get in one readstep. If after this time the client send本文档使用 看云 构建- 29 -
Nginx 中文官方文档nothing, nginx returns error "Request time out" (408).client_max_body_sizesyntax:client_max_body_size sizedefault:client_max_body_size 1mcontext:http, server, locationDirective assigns the maximum accepted body size of client request, indicated by the line
Content-Length in the header of size is greater the given one, then the client gets the error "Request Entity Too Large" (413).It is necessary to keep in mind that the browsers do not know how to correctly show this t_typesyntax:default_type MIME-typedefault:default_type text/plaincontext:http, server, locationAssigns the default MIME-type to be used for files where the standard MIME map doesn't also typesExample:location = / { default_type application/x-ns-proxy-autoconfig;}location = / { rewrite . /; default_type application/x-ns-proxy-autoconfig;}directiosyntax:directio [size|off]default:directio offcontext:http, server, location本文档使用 看云 构建- 30 -
Nginx 中文官方文档The directive enables use of flags O_DIRECT (FreeBSD, Linux), F_NOCACHE (Mac OS X) ordirectio() function (Solaris) for reading files with size greater than specified. This directive disablesuse of sendfile for this request. This directive may be useful for big files: directio 4m;error_pagesyntax:error_page code [ ] [ = | =answer-code ] uri | @named_locationdefault:nocontext:http, server, location, if in locationThe directive specifies the URI, which will be showed for the errors e:error_page 404 /;error_page 502 503 504 /;error_page 403 /;error_page 404 = @fetch;Furthermore, it is possible to change the code of answer to another, for example:error_page 404 =200 /.;If an erroneous answer is processed by the proxied or FastCGI server and this server can returnthe different answer codes, for example, 200, 302, 401 or 404, then it is possible to hide the codereturned:error_page 404 = /;If you wish to return the error code as-is, OMIT the = from the error_page directive:error_page 404 /;if_modified_sincesyntax:if_modified_since [off|exact|before]default:if_modified_since exact本文档使用 看云 构建- 31 -
Nginx 中文官方文档context:http, server, locationThe directive (0.7.24) defines how to compare time of file modification and time in requestheader "If-Modified-Since":off — don't check "If-Modified-Since" request header (0.7.34);exact — exact match;before — file modification time should be less than time in "If-Modified-Since" yntax:index file []default:index ntext:http, server, locationDirective determines the file(s) which will be used as the index. It's possible to use variables in thename of file. The presence of the files is checked in the order of their enumeration. A file with anabsolute path can be put at the end. Example using a variable:index index.$ /;If you want to automatically generate an index from a directory listing, useautoindex alsyntax:internaldefault:nocontext:locationinternal indicates that the matching location can be used only for so called "internal" alFor external requests it will return the error "Not found" (404).Internal requests are the following:requests redirected by the instruction error_pagesubrequests created by the command include virtual of the "ngx_http_ssi_module" modulerequests changed by the instruction rewrite of the "ngx_http_rewrite_module" modulerewriteAn example to prevent clients fetching error pages directly:本文档使用 看云 构建- 32 -
Nginx 中文官方文档error_page 404 /;location / { internal;}Nginx 0.7.x introduces a new syntax for internal locations: @locationExample:location / { root /var/www/html; error_page 404 @40x;}
location @40x { root /var/www/errors/;}keepalive_timeoutsyntax:keepalive_timeout [ time ]default:keepalive_timeout 75context:http, server, locationThe first parameter assigns the timeout for keep-alive connections with the client. The server willclose connections after this optional second parameter assigns the time value in the header Keep-Alive: timeout=timeof the response. This header can convince some browsers to close the connection, so that theserver does not have to. Without this parameter, nginx does not send a Keep-Alive header(though this is not what makes a connection "keep-alive").The parameters can differ from each on how browsers handle the Keep-Alive header:MSIE and Opera ignore the "Keep-Alive: timeout=" keeps the connection alive for about 60-65 seconds, then sends a TCP keeps the connection alive for a long a keeps the connection alive for N plus about 1-10 ror keeps the connection alive for about N seconds.本文档使用 看云 构建- 33 -
Nginx 中文官方文档keepalive_requestssyntax:keepalive_requests ndefault:keepalive_requests 100context:http, server, locationNumber of requests which can be made over a keep-alive _client_header_bufferssyntax:large_client_header_buffers number sizedefault:large_client_header_buffers 4 4k/8kcontext:http, serverDirective assigns the maximum number and size of buffers for large headers to read from request line can not be bigger than the size of one buffer, if the client send a bigger headernginx returns error "Request URI too large" (414).The longest header line of request also must be not more than the size of one buffer, otherwisethe client get the error "Bad request" (400).Buffers are separated only as default the size of one buffer is equal to the size of page, depending on platform this either 4Kor 8K, if at the end of working request connection converts to state keep-alive, then these buffersare _exceptsyntax:limit_except methods {...}default:nocontext:locationDirective limits HTTP-methods, accessible inside the limitation can be used the directives of modules ngx_http_access_module andngx_http_auth_basic_module:本文档使用 看云 构建- 34 -
Nginx 中文官方文档limit_except GET { allow 192.168.1.0/32; deny all;}limit_ratesyntax:limit_rate speeddefault:nocontext:http, server, location, if in locationDirective assigns the speed of transmission of the answer to client. Speed is assigned in the bytesper second. Limitation works only for one connection, i.e., if client opens 2 connections, thentotal velocity will be 2 times higher then the limit it is necessary to limit speed for the part of the clients at the
server level, based on some kindof condition - then this directive does not apply. Instead you should specify the limit byassigning the value to the $limit_rate variable, as shown below:server { if ($slow) { set $limit_rate 4k; }}limit_rate_aftersyntax:limit_rate_after timedefault:limit_rate_after 1mcontext:http, server, location, if in locationThe directive limits speed only after the first part was _rate_after 1m;limit_rate 100k;listensyntax:listen address:port [ default [ backlog=num | rcvbuf=size | sndbuf=size |accept_filter=filter | deferred | bind | ssl ] ]本文档使用 看云 构建- 35 -
Nginx 中文官方文档default:listen 80context:serverThe
listen directive specifies the address and port accepted by the enclosing server {...} block. It ispossible to specify only an address, only a port, or a server name as the 127.0.0.1:8000;listen 127.0.0.1;listen 8000;listen *:8000;listen localhost:8000;IPv6 address(0.7.36) are set in square brackets:listen [::]:8000;
listen [fe80::1];When Linux (in contrast to FreeBSD) binds IPv6 [::], it will also bind the corresponding IPv4address. If other non IPv6 server definitions already used this, the bind will fail. By using explicitaddresses instead of [::] this will not be a problem. It is also possible to specify that this listendirective is only to bind the IPv6 address with use of the "default ipv6only=on" option. Note thatthis only affect this listen directive, the same server {...} block may very well listen to IPv4 as well,specified by other listen [2a02:750:5::123]:80;listen [::]:80 default ipv6only=on;If only address is given, the default port is the directive has the
default parameter, then the enclosing server {...} block will be the defaultserver for the address:port pair. This is useful for name-based virtual hosting where you wish tospecify the default server block for hostnames that do not match any [#server_nameserver_name] directives. If there are no directives with the default parameter, then the defaultserver will be the first server block in which the address:port pair listen directive accepts several parameters, specific to the system calls listen(2) and
bind(2). These parameters must follow the default g=num -- is assigned parameter backlog in call listen(2). By default backlog equals -=size -- assigned to the parameter SO_RCVBUF for the listening =size -- assigned to the parameter SO_SNDBUF for the listening socket.本文档使用 看云 构建- 36 -
Nginx 中文官方文档accept_filter=filter -- is assigned name accept-filter.. It works only to FreeBSD, it is possible to use two filters -- dataready and httpready. On thesignal -HUP accept-filter it is possible to change only in the quite last versions FreeBSD: 6.0, 5.4-STABLE and ed -- indicates to use that postponed accept(2) on Linux with. the aid of option TCP_DEFER_ -- indicates that it is necessary to make bind(2) separately. for this pair of address:port. The fact is that if are described several directives listen with theidentical port, but by different addresses and one of the directives listen listens to on alladdresses for this port (*:port), then nginx will make bind(2) only to *:port. It is necessary toconsider that in this case for determining the address, on which the connections arrive, is donethe system call getsockname(). But if are used parameters backlog, rcvbuf, sndbuf, accept_filteror deferred, then it is always done separately for this pair of address:port bind(2).ssl -- parameter (0.7.14) not related to listen(2) and bind(2) syscalls. but instead specifies that connections accepted on this port should work in SSL mode. Thisallows to specify compact configurations for servers working with both HTTP and HTTPS. Forexample:listen 80;listen 443 default ssl;Example of the use of the parameters:listen 127.0.0.1 default accept_filter=dataready backlog=1024;locationsyntax:location [=|~|~|^~] /uri/ { ... }*default:nocontext:serverThis directive allows different configurations depending on the URI. It can be configured usingboth literal strings and regular expressions. To use regular expressions, you must use the a prefix:1. ~* for case insensitive matching2. ~ for case sensitive matchingTo determine which
location directive matches a particular query, the literal strings are checked本文档使用 看云 构建- 37 -
Nginx 中文官方文档first. Literal strings match the beginning portion of the query and are case-sensitive - the mostspecific match will be used (see below on how nginx determines this). Afterwards, regularexpressions are checked in the order defined in the configuration file. The first regular expressionto match the query will stop the search. If no regular expression matches are found, the resultfrom the literal string search is are two ways to modify this behavior. The first is to use the prefix "=", which matches anexact query only. If the query matches, then searching stops and the request is handledimmediately. For example, if the request "/" occurs frequently, then using "location = /" willexpedite the processing of this second is to use the prefix ^~. This prefix is used with a literal string and tells nginx to notcheck regular expressions if the path provided is a match. For instance, "location ^~ /images/"would halt searching if the query begins with /images/ - all regular expression directives wouldnot be summarize, the order in which directives are checked is as follows:1. Directives with the = prefix that match the query exactly. If found, searching stops.2. All remaining directives with conventional strings. If this match used the ^~ prefix,searching stops.3. Regular expressions, in the order they are defined in the configuration file.4. If #3 yielded a match, that result is used. Otherwise, the match from #2 is is important to know that nginx does the comparison against decoded URIs. For example, ifyou wish to match "/images/%20/test", then you must use "/images/ /test" to determine e:本文档使用 看云 构建- 38 -
Nginx 中文官方文档location = / { # matches the query / only. [ configuration A ]
}location / { # matches any query, since all queries begin with /, but regular # expressions and any longer conventional blocks will be # matched first. [ configuration B ]
}location ^~ /images/ { # matches any query beginning with /images/ and halts searching, # so regular expressions will not be checked. [ configuration C ]
}location ~* .(gif|jpg|jpeg)$ { # matches any request ending in gif, jpg, or jpeg. However, all # requests to the /images/ directory will be handled by # Configuration C.
[ configuration D ]
}Example requests:/ -> configuration A/documents/ -> configuration B/images/ -> configuration C/documents/ -> configuration DNote that you could define these 4 configurations in any order and the results would remain thesame. While nested locations are allowed by the configuration file parser, their use is discouragedand may produce unexpected nginx Determines Which Path MatchesMost users will not need to know how nginx internally determines which path to use - know thatit will choose the "most specific" match for your URI in a speedy and efficient manner. For thosethat are curious, however, read path strings are sorted alphabetically. nginx then proceeds to search down the list looking formatches until the request URI has a "higher" value then the current string in the sorted list. This isdetermined using the family of strcmp() functions - once strcmp() returns 1, then searchingstops. Once searching stops, the last string which matched is used.本文档使用 看云 构建- 39 -
Nginx 中文官方文档For example, lets say we have the following paths://a/apple/bananaNow, lets say the server gets the path "/az". nginx would begin search down this list. First, "/"would match, but "/ is less than "/az" so searching continues. "/a" also matches, but "/a" is stillless than "/az" so we continue again. "/apple" does not match. The next string, "/banana", isgreater than "/az" so searching stops and the last match, "/a", would be LocationsLater versions of Nginx (>0.7.x) have Named Locations. These are location blocks that start withan @ symbol, and are treated similar to internal locations except that they preserve the originalURI on internal redirects for error_page or try_files on / {**************************;}location @joomla { rewrite ^(.*)$ /?q=$1 last;}log_not_foundsyntax:log_not_found [on|off]default:log_not_found oncontext:http, server, locationThe directive enables or disables messages in error_log about files not found on _subrequestsyntax:log_subrequest [on|off]default:log_subrequest offcontext:http, server, locationThe directive enables or disables messages in access_log about sub-requests such as rewrite rulesand/or SSI requests.本文档使用 看云 构建- 40 -
Nginx 中文官方文档msie_paddingsyntax:msie_padding [on|off]default:msie_padding oncontext:http, server, locationThis directive enables or disables the the msie_padding feature for MSIE browsers. When this isenabled, nginx will pad the size of the response body to a minimum of 512 bytes, for responseswith a status code above or equal to padding prevents the activation of "friendly" HTTP error pages in MSIE, so as to not hide themore-informative error pages from the that Chromium/Chrome have "friendly" HTTP error pages as well, but this feature will notsend them the _refreshsyntax:msie_refresh [on|off]default:msie_refresh offcontext:http, server, locationThis directive allows or forbids issuing a refresh instead of doing a redirect for _file_cachesyntax:open_file_cache max = N [inactive = time] | offdefault:open_file_cache offcontext:http, server, locationThe directive sets the cache activity on. These information can be stored:Open file descriptors, information with their size and modification time;Information about the existence of directories;Error information when searches for a file - no file, do not have rights to read, etc. See alsoopen_file_cache_errorsOptions directive:max - specifies the maximum number of entries in the cache. When the cache overflows, thelongest-used items(LRU) will be removed;inactive - specifies the time when the cached item is removed, if it has not been downloaded本文档使用 看云 构建- 41 -
Nginx 中文官方文档during that time, the default is 60 seconds;off - prohibits the cache e: open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2; open_file_cache_errors on;open_file_cache_errorssyntax:open_file_cache_errors on | offdefault:open_file_cache_errors offcontext:http, server, locationThe directive specifies to cache errors or not when searching a _file_cache_min_usessyntax:open_file_cache_min_uses numberdefault:open_file_cache_min_uses 1context:http, server, locationThe directive defines the minimum use number of a file within the time specified in the directiveparameter inactive in open_file_cache. ?If use more than the number, the file descriptor willremain open in the _file_cache_validsyntax:open_file_cache_valid timedefault:open_file_cache_valid 60context:http, server, locationThe directive specifies the time when need to check the validity of the information about the itemin open_file_ze_server_namessyntax:optimize_server_names [ on|off ]default:optimize_server_names on本文档使用 看云 构建- 42 -
Nginx 中文官方文档context:http, serverDirective activates or deactivates optimization of host name checks for name-based particular, the check influences the name of the host used in redirects. If optimization is on,and all name-based servers listening on one address:port pair have identical configuration, thennames are not checked during request execution and redirects use first server redirect must use host name passed by the client, then the optimization must be turned : this directive is deprecated in nginx 0.7.x, use server_name_in_redirect _in_redirectsyntax:port_in_redirect [ on|off ]default:port_in_redirect oncontext:http, server, locationDirective allows or prevents port indication in redirects handled by port_in_redirect is on, then Nginx will not add the port in the url when the request ive_error_pagessyntax:recursive_error_pages [on|off]default:recursive_error_pages offcontext:http, server, locationrecursive_error_pages enables or disables following a chain of error_page ersyntax:resolver addressdefault:nocontext:http, server, locationTODO: Descriptionresolver_timeoutsyntax:resolver_timeout time本文档使用 看云 构建- 43 -
Nginx 中文官方文档default:30context:http, server, locationResolver timeout in ntax:root pathdefault:root htmlcontext:http, server, location, if in locationroot specifies the document root for the requests. For example, with this configurationrootlocation /i/ { root /spool/w3;}A request for "/i/" will return the file "/spool/w3/i/". You can use variables in : Keep in mind that the root will still append the directory to the request so that a request fornote:"/i/" will not look in "/spool/w3/" like might happen in an Apache-like aliasconfiguration where the location match itself is dropped. Use the alias directive to achieve theApache-like y_anysyntax:satisfy_any [ on|off ]default:satisfy_any offcontext:locationDirective solves access with at least one successful checking, executed by modulesNginxHttpAccessModule orNginxHttpAuthBasicModule:location / { satisfy_any on; allow 192.168.1.0/32; deny all; auth_basic "closed site"; auth_basic_user_file conf/htpasswd;}本文档使用 看云 构建- 44 -
Nginx 中文官方文档send_timeoutsyntax:send_timeout the timedefault:send_timeout 60context:http, server, locationDirective assigns response timeout to client. Timeout is established not on entire transfer ofanswer, but only between two operations of reading, if after this time client will take nothing,then nginx is shutting down the lesyntax:sendfile [ on|off ]default:sendfile offcontext:http, server, locationDirective activate or deactivate the usage of sendfile().serversyntax:server {...}default:nocontext:httpDirective assigns configuration for the virtual is no separation of IP and name-based (the Host header of the request) d, the directive listen is used to describe all addresses and ports on which incomingconnections can occur, and in directive server_name indicate all names of the _namesyntax:server_name name [... ]default:server_name hostnamecontext:serverThis directive performs two actions:Compares the Host header of the incoming HTTP request against the server { ... } blocks inthe Nginx configuration files and selects the first one that matches. This is how virtual serversvirtual servers本文档使用 看云 构建- 45 -
Nginx 中文官方文档are defined. Server names are processed in the following order:1. full, static names2. names with a wildcard at the start of the name — *.3. names with a wildcard at the end of the name — e.4. names with regular expressionsIf there is no match, a [#server server { ... }] block in the configuration file will be used based onthe following order:1. the server block with a matching listen directive marked as default2. the first server block with a matching listen directive (or implicit listen 80;)Sets the server name that will be used in HTTP redirects if server_name_in_redirect is e:server { server_name ;}The first name becomes the basic name of server. By default the name of the machine(hostname) is is possible to use "*" for replacing the first or the last part of the name:server { server_name *. e.*;}Two of the above given names can be combined into one:server { server_name .;}It is also possible to use regular expressions in server names, prepending the name with a tilde"~" like so:server { server_name ~^wwwd+.$;}本文档使用 看云 构建- 46 -
Nginx 中文官方文档The basic name of server is used in an HTTP redirects, if no Host header was in client request orthat header does not match any assigned server_name. You can also use just "" to force Nginx touse the Host header in the HTTP redirect (note that "" cannot be used as the first name, but youcan use a dummy name such as "_" instead):server { server_name *;}server { server_name _ *;}Note that this has changed in 0.6.x and is now:server { server_name _;}Since nginx 0.7.12, an empty server name is supported, to catch the requests without "Host"header:server {server_name "";}server_name_in_redirectsyntax:server_name_in_redirect on|offdefault:server_name_in_redirect oncontext:http, server, locationIf server_name_in_redirect is on, then Nginx will use the first value of the server_name directivefor redirects. If server_name_in_redirect is off, then nginx will use the requested Host _names_hash_max_sizesyntax:server_names_hash_max_size numberdefault:server_names_hash_max_size 512context:http本文档使用 看云 构建- 47 -
Nginx 中文官方文档The maximum size of the server name hash tables. For more detail see the description of tuningthe hash tables in Nginx _names_hash_bucket_sizesyntax:server_names_hash_bucket_size numberdefault:server_names_hash_bucket_size 32/64/128context:httpDirective assigns the size of basket in the hash-tables of the names of servers. This value bydefault depends on the size of the line of processor cache. For more detail see the description oftuning the hash tables in Nginx _tokenssyntax:server_tokens on|offdefault:server_tokens oncontext:http, server, locationWhether to send the Nginx version number in error pages and Server _nodelaysyntax:tcp_nodelay [on|off]default:tcp_nodelay oncontext:http, server, locationThis directive allows or forbids the use of the socket option TCP_NODELAY. Only included in
keep-alive can read more about the TCP_NODELAY socket option _nopushsyntax:tcp_nopush [on|off]default:tcp_nopush offcontext:http, server, locationThis directive permits or forbids the use of the socket options TCP_NOPUSH on FreeBSD or
TCP_CORK on Linux. This option is only available when using sendfile.本文档使用 看云 构建- 48 -
版权声明:本文标题:Nginx 中文官方文档 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1704361551h456166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论