模块依赖性
gzip 模块需要 zlib 库 rewrite 模块需要 pcre 库 ssl 功能需要 openssl 库预先编译好的安装包
Nginx在一些Linux发行版和BSD的各个变种版本的安装包仓库中都会有,通过各个系统自带的软件包管理方法即可安装。需要注意的是,很多预先编译好的安装包都比较陈旧,大多数情况下还是推荐直接从源码编译。
Ubuntu(Debian)软件包安装
apt-get update
apt-get install nginx
http://wiki.ubuntu.org.cn/Nginx
1. 官方源码下载 http://nginx.org
2. 解压缩
tar zxvf nginx-1.0.12.tar.gz
3. 编译安装
如:
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --with-http_ssl_module
* Ubuntu10.04安装openssl
执行如下操作来安装openssl及其开发函数库:
$ sudo apt-get install openssl
$ sudo apt-get install libssl0.9.8
$ sudo apt-get install libssl-dev
PCRE库安装
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
编译参数说明:
--prefix=
— defines a directory that will keep server files. This same directory will also be used for all relative paths set bypath
configure
(except for paths to libraries sources) and in thenginx.conf
configuration file. It is set to the/usr/local/nginx
directory by default.Nginx安装路径。如果没有指定,默认为 /usr/local/nginx。
--sbin-path=
— sets the name of an nginx executable file. This name is used only during installation. By default the file is namedpath
.prefix
/sbin/nginxNginx可执行文件安装路径。只能安装时指定,如果没有指定,默认为<prefix>/sbin/nginx。
--conf-path=
— sets the name of anpath
nginx.conf
configuration file. If needs be, nginx can always be started with a different configuration file, by specifying it in the command-line parameter-c
. By default the file is namedfile
.prefix
/conf/nginx.conf在没有给定-c选项下默认的nginx.conf的路径。如果没有指定,默认为<prefix>/conf/nginx.conf。
--pid-path=
— sets the name of an nginx.pid file that will store the process ID of the main process. After installation, the file name can always be changed in thepath
nginx.conf
configuration file using the pid directive. By default the file is named
.prefix
/logs/nginx.pid指定nginx.pid的文件名,安装后该名字可以在nginx.cong文件中修改。如果没有指定,默认为 <prefix>/logs/nginx.pid。
--error-log-path=
— sets the name of the primary error, warnings, and diagnostic file. After installation, the file name can always be changed in thepath
nginx.conf
configuration file using the error_log directive. By default the file is named
.prefix
/logs/error.log在nginx.conf中没有指定error_log指令的情况下,默认的错误日志的路径。如果没有指定,默认为 <prefix>/logs/error.log。
--http-log-path=
— sets the name of the primary request log file of the HTTP server. After installation, the file name can always be changed in thepath
nginx.conf
configuration file using the access_log directive. By default the file is named
.prefix
/logs/access.log--user=
— sets the name of an unprivileged user whose credentials will be used by worker processes. After installation, the name can always be changed in thename
nginx.conf
configuration file using the user directive. The default user name is nobody.在nginx.conf中没有指定user指令的情况下,默认的nginx使用的用户。如果没有指定,默认为 nobody。
--group=
— sets the name of a group whose credentials will be used by worker processes. After installation, the name can always be changed in thename
nginx.conf
configuration file using the user directive. By default, a group name is set to the name of an unprivileged user.在nginx.conf中没有指定user指令的情况下,默认的nginx使用的组。如果没有指定,默认为 nobody。
--with-select_module
--without-select_module
— enables or disables building a module that allows the server to work with theselect()
method. This module is built automatically if the platform does not appear to support more appropriate methods such as kqueue, epoll, rtsig, or /dev/poll.--with-poll_module
--without-poll_module
— enables or disables building a module that allows the server to work with thepoll()
method. This module is built automatically if the platform does not appear to support more appropriate methods such as kqueue, epoll, rtsig, or /dev/poll.--without-http_gzip_module
— disables building a module that compresses responses of an HTTP server. The zlib library is required to build and run this module.--without-http_rewrite_module
— disables building a module that allows an HTTP server to redirect requests and change URI of requests. The PCRE library is required to build and run this module. The module is experimental — its directives may change in the future.禁用 ngx_http_rewrite_module.
--without-http_proxy_module
— disables building an HTTP server proxying module.--with-http_ssl_module
— enables building a module that adds the HTTPS protocol support to an HTTP server. This module is not built by default. The OpenSSL library is required to build and run this module.开启HTTP SSL模块,使NGINX可以支持HTTPS请求。这个模块需要已经安装了OPENSSL
--with-pcre=
— sets the path to the sources of the PCRE library. The library distribution (version 4.4 — 8.21) needs to be downloaded from the PCRE site and extracted. The rest is done by nginx's ./configure and make. The library is required for regular expressions support in the location directive and for the ngx_http_rewrite_module module.path
指定PCRE库路径。(PCRE为正则表达式库)
--with-pcre-jit
— builds the PCRE library with “just-in-time compilation” support.--with-zlib=
— sets the path to the sources of the zlib library. The library distribution (version 1.1.3 — 1.2.5) needs to be downloaded from the zlib site and extracted. The rest is done by nginx's ./configure and make. The library is required for thengx_http_gzip_module module.path
--with-cc-opt=
— sets additional parameters that will be added to the CFLAGS variable. When using the system PCRE library under FreeBSD,parameters
--with-cc-opt="-I /usr/local/include"
should be specified. If the number of files supported byselect()
needs to be increased it can also be specified here such as this:--with-cc-opt="-D FD_SETSIZE=2048"
.--with-ld-opt=
— sets additional parameters that will be used during linking. When using the system PCRE library under FreeBSD,parameters
--with-ld-opt="-L /usr/local/lib"
should be specified.
示例:
./configure
--sbin-path=/usr/local/nginx/nginx
--conf-path=/usr/local/nginx/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-http_ssl_module
--with-pcre=../pcre-4.4
--with-zlib=../zlib-1.1.3