• Nginx简介与安装


    昨天在电脑上安装了CentOS 6.2,为的是学习Linux和nginx服务器的配置,并学习阅读nginx的源码。

    Web服务器也称为WWW服务器,HTTP服务器,主要功能是提供网页浏览服务。主流的Web服务器有Apache,Nginx,Lighttpd,IIS等。到目前为止,Apache仍然是市场占有率最高的Web服务器,市场占有率超过60%。

    主要的Web服务器的市场占有率如下图所示:(来源:http://news.netcraft.com/archives/category/web-server-survey/

    DeveloperJune 2012PercentJuly 2012PercentChange
    Apache 448,452,703 64.33% 409,185,675 61.45% -2.89
    Microsoft 95,891,537 13.76% 97,385,377 14.62% 0.87
    nginx 72,881,755 10.46% 73,833,173 11.09% 0.63
    Google 22,464,345 3.22% 22,931,169 3.44% 0.22

    1、Apache
    Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。Apache能取得如此成功并不足为奇:它免费、稳定且性能卓越;但Apache能取得如此佳绩的另一个原因是,当时互联网刚刚兴起时,Apache是第一个可用的Web应用服务器,人们没有其他的选择。
    对于那些需要更强大的Web应用服务器(比如大小、可定制、响应速度、可扩展性等方面)的人而言,Apache明显不符合他们的要求,寻找Apache的替代者是更好的选择。
    2、Lighttpd
    Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能。
    3、Nginx(Ngwsx)

    Nginx是十分轻量级的HTTP服务器,是一个高性能的HTTP和反向代理服务器,Nginx以事件驱动的方式编写,所以有非常好的性能,同时也是一个非常高效的反向代理、负载平衡。其拥有匹配 Lighttpd的性能,同时还没有Lighttpd的内存泄漏问题。

    Nginx("engine x")是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Nginx是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。在辆,已经有新浪博客、网易新闻、Discuz!官方论坛、豆瓣、淘宝等大型互联网企业使用Nginx,尤其是淘宝,基于Nginx开发出了深度定制开发出了自己的Web服务器Tengine,并于去年开源。

    Nginx与Apache、Lighttpd的综合对比:

    server Apache Nginx      Lighttpd
    Proxy代理 非常好 非常好 一般
    Rewriter 非常好 一般
    Fastcgi 不好 非常好
    热部署 不支持 支持 不支持
    系统压力比较 很大 很小 比较小
    稳定性 非常好 不好
    安全性 一般 一般
    技术支持 非常好 很少 一般
    静态文件处理 一般 非常好
    Vhosts虚拟主机 支持 支持 支持
    反向代理 一般 非常好 一般
    Session sticky 支持 不支持 不支持
    量级 重量级 轻量 轻量
    复杂度(安装、配置) 较复杂 简单 简单

    我的安装方式是先安装LNMP(http://lnmp.org/),它是一个软件包,里面包含了Nginx,MySQL,PHP等软件套件,而且安装简单。

    安装方法:tar zxvf lnmp0.9-full.tar.gz,将lnmp软件包解压,执行cd命令cd lnmp0.9-full进入目录lnmp0.9-full,如果是CentOS,则执行./centos.sh 2>&1 | tee lnmp.log,如果是ubuntu,则执行./ubuntu.sh 2>&1 | tee lnmp.log,进入自动安装过程,中间过程都有很明确的提示。

    安装完成后,再升级安装Nginx。我安装的Nginx版本是nginx-1.2.1,安装过程也和其他的软件类似,./configure,make,make install。注意,在./configure的时候,有可选的编译选项,可以通过命令./configure --help命令查看编译选项。

    我开始采用的是默认状态进行configure,但是在后来的start server过程中出现了问题,后来在找原因,原来是在./configure的时候,应该加入参数 --with-http_stub_status_module,作用是启用server status页。完整的命令是:./configure --with-http_stub_status_module。

    Nginx的启动:Nginx默认安装文件夹是/usr/local/nginx,所以命令为:/usr/local/nginx/sbin/nginx,Nginx会默认加载其安装目录的conf子目录中的nginx.conf文件(/usr/local/nginx/conf/nginx.conf)。

    Nginx的停止:可以通过ps命令来查找Nginx的主进程号:ps -ef | grep nginx。

    lnmp的默认网页存在/home/wwwroot/目录中。自己编写的PHP文件和其他网页文件也存在此处。

    这些是我关于安装lnmp以及升级Nginx的一些过程,有不足之处请各位方家指教。

    附:Nginx编译选项:

    configure determines the features of system and, in particular, the methods, which nginx can use for handling connections. Finally it creates the Makefile.
    编译配置决定了系统的特征,尤其在nginx处理连接的方法。最后他将创建makefile。
    configure supports the following options:
    编译配置支持以下选项:
    --prefix=<path> - The path relative to which all other Nginx paths will resolve. If not specified, defaults to /usr/local/nginx.
    --prefix=<path> Nginx的安装目录,默认安装在/usr/local/nginx

    --sbin-path=<path> - The path to the nginx executable. Only used for installation. If not specified defaults to <prefix>/sbin/nginx.
    --sbin-path=<path> nginx可执行命令的路径,仅在安装是指定。如果未指定,默认安装在<prefix>/sbin/nginx

    --conf-path=<path> - The default location of nginx.conf if no -c parameter is provided. If not provided, defaults to <prefix>/conf/nginx.conf.
    --conf-path=<path> 在启动是没有-c参数时,nginx的默认启动配置nginx.conf文件。如果未指定,默认路径<prefix>/conf/nginx.conf

    --pid-path=<path> - The path to nginx.pid, if not set via the "pid" directive in nginx.conf. If not provided, defaults to <prefix>/logs/nginx.pid.
    --pid-path=<path> 指定nginx.pid的路径,若未指定,默认路径<prefix>/logs/nginx.pid

    --lock-path=<path> - The path to the nginx.lock file. If not provided, defaults to <prefix>/logs/nginx.lock.
    --lock-path=<path> 指定nginx.lock文件的路径,若未指定,默认路径<prefix>/logs/nginx.lock.

    --error-log-path=<path> - The location of the error log if not set via the "error_log" in nginx.conf. If not set, defaults to <prefix>/logs/error.log.
    --error-log-path=<path> 指定error_log的路径,若未指定,默认<prefix>/logs/error.log

    --http-log-path=<path> - The location of the access log if not set via the "access_log" directive in nginx.conf. If not set, defaults to <prefix>/logs/access.log.
    --http-log-path=<path> 指定access_log的路径,若未指定,默认<prefix>/logs/access.log

    --user=<user> - The default user that nginx will run as if not set in nginx.conf via the "user" directive. If not set, defaults to "nobody".
    --user=<user> nginx的运行用户,若未指定,默认为nobody。(也可在nginx.conf中指定)

    --group=<group> - The default group that nginx will run under if not set via the "user" directive in nginx.conf. If not set defaults to "nobody".
    --user=<user> nginx的运行属组,若未指定,默认为nobody。(也可在nginx.conf中指定)

    --builddir=DIR - Set the build directory
    --builddir=DIR 设置build目录

    --with-rtsig_module - Enable rtsig module
    --with-rtsig_module 开启rtsig模块

    --with-select_module --without-select_module - Whether or not to enable the select module. This module is enabled by default if a more suitable method such as kqueue, epoll, rtsig or /dev/poll is not discovered by configure.
    --with-select_module --without-select_module 是否开启select模块。若没有更适合的kqueue,epoll,rtsig或者/dev/poll 方法在配置中指定,将默认开启。

    --with-poll_module --without-poll_module - Whether or not to enable the poll module. This module is enabled by default if a more suitable method such as kqueue, epoll, rtsig or /dev/poll is not discovered by configure.
    --with-poll_module --without-poll_module 是否开启poll模块。若没有更适合的kqueue, epoll, rtsig or /dev/poll 方法在配置中指定,将默认开启。

    --with-http_ssl_module - Enable ngx_http_ssl_module. Enables SSL support and the ability to handle HTTPS requests. Requires OpenSSL. On Debian, this is libssl-dev.
    --with-http_ssl_module 开启ngx_http_ssl_module。开启SSL支持,用来处理HTTPS请求。依赖OpenSSL。在Debian系统上,需要libssl-dev。

    --with-http_realip_module - Enable ngx_http_realip_module
    --with-http_realip_module 开启ngx_http_realip_module

    --with-http_addition_module - Enable ngx_http_addition_module
    --with-http_addition_module 开启ngx_http_addition_module

    --with-http_sub_module - Enable ngx_http_sub_module
    --with-http_sub_module 开启ngx_http_sub_module

    --with-http_dav_module - Enable ngx_http_dav_module
    --with-http_dav_module 开启ngx_http_dav_module

    --with-http_flv_module - Enable ngx_http_flv_module
    --with-http_flv_module 开启ngx_http_flv_module

    --with-http_stub_status_module - Enable the "server status" page
    --with-http_stub_status_module 启动服务器"server status"页,检测服务器状态

    --without-http_charset_module - Disable ngx_http_charset_module
    --without-http_charset_module 关闭ngx_http_charset_module

    --without-http_gzip_module - Disable ngx_http_gzip_module. Requires zlib if enabled.
    --without-http_gzip_module 关闭ngx_http_gzip_module. 要求zlib开启.

    --without-http_ssi_module - Disable ngx_http_ssi_module
    --without-http_ssi_module 关闭ngx_http_ssi_module

    --without-http_userid_module - Disable ngx_http_userid_module
    --without-http_userid_module 关闭ngx_http_userid_module

    --without-http_access_module - Disable ngx_http_access_module
    --without-http_access_module 关闭ngx_http_access_module

    --without-http_auth_basic_module 关闭ngx_http_auth_basic_module

    --without-http_autoindex_module 关闭ngx_http_autoindex_module

    --without-http_geo_module 关闭ngx_http_geo_module

    --without-http_map_module 关闭ngx_http_map_module

    --without-http_referer_module 关闭ngx_http_referer_module

    --without-http_rewrite_module 关闭ngx_http_rewrite_module. 要求 PCRE 开启.

    --without-http_proxy_module - Disable ngx_http_proxy_module
    --without-http_proxy_module 关闭ngx_http_proxy_module

    --without-http_fastcgi_module - Disable ngx_http_fastcgi_module
    --without-http_fastcgi_module 关闭ngx_http_fastcgi_module

    --without-http_memcached_module - Disable ngx_http_memcached_module
    --without-http_memcached_module 关闭ngx_http_memcached_module

    --without-http_limit_zone_module - Disable ngx_http_limit_zone_module
    --without-http_limit_zone_module 关闭ngx_http_limit_zone_module

    --without-http_empty_gif_module - Disable ngx_http_empty_gif_module
    --without-http_empty_gif_module 关闭ngx_http_empty_gif_module

    --without-http_browser_module - Disable ngx_http_browser_module
    --without-http_browser_module 关闭ngx_http_browser_module

    --without-http_upstream_ip_hash_module - Disable ngx_http_upstream_ip_hash_module
    --without-http_upstream_ip_hash_module 关闭ngx_http_upstream_ip_hash_module

    --with-http_perl_module - Enable ngx_http_perl_module
    --with-http_perl_module 关闭ngx_http_perl_module

    --with-perl_modules_path=PATH - Set path to the perl modules
    --with-perl_modules_path=PATH 设置perl modules的路径

    --with-perl=PATH - Set path to the perl binary
    --with-perl=PATH 设置perl的运行目录

    --http-client-body-temp-path=PATH - Set path to the http client request body temporary files. If not set, defaults to <prefix>/client_body_temp
    --http-client-body-temp-path=PATH 设置http访问正文信息的临时文件路径。如果没有设置PATH,默认<prefix>/client_body_temp

    --http-proxy-temp-path=PATH - Set path to the http proxy temporary files. If not set, defaults to <prefix>/proxy_temp
    --http-proxy-temp-path=PATH 设置代理的临时文件路径。如果没有设置PATH,默认<prefix>/proxy_temp

    --http-fastcgi-temp-path=PATH - Set path to the http fastcgi temporary files. If not set, defaults to <prefix>/fastcgi_temp
    --http-fastcgi-temp-path=PATH 设置http fastcgi 临时文件的路径。如果没有设置PATH,默认<prefix>/fastcgi_temp

    --without-http 关闭HTTP server功能。

    --with-mail 启用IMAP4/POP3/SMTP proxy module

    --with-mail_ssl_module 启用ngx_mail_ssl_module

    --with-cc=PATH - Set path to C compiler
    --with-cc=PATH 设置c编译器的路径

    --with-cpp=PATH - Set path to C preprocessor
    --with-cpp=PATH 设置c处理器的路径

    --with-cc-opt=OPTIONS - Additional parameters which will be added to the variable CFLAGS. With the use of the system library PCRE in FreeBSD, it is necessary to indicate --with-cc-opt="-I /usr/local/include". If we are using select() and it is necessary to increase the number of file descriptors, then this also can be assigned here: --with-cc-opt="-D FD_SETSIZE=2048".
    --with-cc-opt=OPTIONS CFLAGS新增的参数. 在FreeBSD下使用系统库PCRE, 有必要指定--with-cc-opt="-I /usr/local/include". 如果使用select()功能,有必要增加文件描述符的数据量, 可以这样设置: --with-cc-opt="-D FD_SETSIZE=2048".

    --with-ld-opt=OPTIONS - Additional parameters passed to the linker. With the use of the system library PCRE in FreeBSD, it is necessary to indicate --with-ld-opt="-L /usr/local/lib".
    --with-ld-opt=OPTIONS 添加传递给linker的参数. 在使用freebsd系统库PCRE时,有必要指定--with-ld-opt="-L /usr/local/lib".

    --with-cpu-opt=CPU - Build for specified CPU, the valid values: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
    --with-cpu-opt=CPU 为特定的CPU构建包,有效值有: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64

    --without-pcre - Disable PCRE library usage. Also disables HTTP rewrite module. PCRE is also required for regular expressions in "location" directive.
    --without-pcre 关闭PCRE库. 同时会关闭rewrite. PCRE在"location"段中的正则表达式中需要用到。

    --with-pcre=DIR - Set path to PCRE library sources.
    --with-pcre=DIR 指定PCRE库的源文件路径.

    --with-pcre-opt=OPTIONS - Set additional options for PCRE building.
    --with-pcre-opt=OPTIONS 设置PCRE更多选项.

    --with-md5=DIR - Set path to md5 library sources.
    --with-md5=DIR 指定md5库的源文件的路径.

    --with-md5-opt=OPTIONS - Set additional options for md5 building.
    --with-md5-opt=OPTIONS 设置md5的更多选项.

    --with-md5-asm - Use md5 assembler sources.
    --with-md5-asm 使用md5的汇编源.

    --with-sha1=DIR - Set path to sha1 library sources.
    --with-sha1=DIR 指定sha1库的源文件的路径.

    --with-sha1-opt=OPTIONS - Set additional options for sha1 building.
    --with-sha1-opt=OPTIONS 设置sha1的更多选项.

    --with-sha1-asm - Use sha1 assembler sources.
    --with-sha1-asm 使用sha1的汇编源.

    --with-zlib=DIR - Set path to zlib library sources.
    --with-zlib=DIR 指定zlib库的源文件路径.

    --with-zlib-opt=OPTIONS - Set additional options for zlib building.
    --with-zlib-opt=OPTIONS 设置zlib的更多选项.

    --with-zlib-asm=CPU - Use zlib assembler sources optimized for specified CPU, valid values are: pentium, pentiumpro
    --with-zlib-asm=CPU 使用为特定CPU优化的汇编源, 有效值: pentium, pentiumpro

    --with-openssl=DIR - Set path to OpenSSL library sources
    --with-openssl=DIR 指定OpenSSL的库的源文件路径

    --with-openssl-opt=OPTIONS - Set additional options for OpenSSL building
    --with-openssl-opt=OPTIONS 设置OpenSSL的更多选项。

    --with-debug - Enable debug logging
    --with-debug 开启debug日志

    --add-module=PATH - Add in a third-party module found in directory PATH
    --add-module=PATH 添加在PATH中指定的第三方模块

    Options may vary slightly between versions. Always check ./configure --help for the current list.
    这些选项在不同的版本中有些许的不同,使用./configure --help 命令查看当前版本支持的选项。

  • 相关阅读:
    eval是只读数据,bind是可更新的.
    数据库中的html在页面上显示
    kindeditor asp.net 模板问题 clientidmode="Static"
    我对if(!this.IsPostBack)的理解
    asp.net正则表达式
    由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。
    IIS7错误:不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况。锁定是默认设置的(overrideModeDefault="Deny")...
    Microsoft.AspNet.FriendlyUrls发布到IIS后404报错的解决方案
    jQuery 绑定事件
    jQuery 位置
  • 原文地址:https://www.cnblogs.com/juventus/p/2614314.html
Copyright © 2020-2023  润新知