您的位置:首页 > 运维架构 > Nginx

nginx学习总结一(基本介绍和编译参数详解)

2011-01-06 22:25 357 查看
一对nginx的初步了解。

1.什么是nginx呢?

nginx是俄罗斯人(伊戈尔,塞索耶夫)编写的一种高性能的http和反向代理服务器。

2.为什么nginx逐渐代替apache呢?

来源他的几大优点:

①它可以高并发连接

nginx采用了最新的epoll(linux内核)和kqueue(freebsd)网络I/O模型,而apache采用传统的select模型

,其比较稳定的prefork模式为多进程模式,需要经常派生子进程,所以消耗的cup比nginx多很多。

要了解apache工作模式,具体见apache模式介绍那篇。

②内存消耗少

在服务器3W并发连接下,开启10个nginx进程才消耗150MB的内存(15MBX10=150MB),开启的64个php-cgi进程才消耗 1280MB内存(20MBX64=1280MB),单台nginx+php5-cgi处理php动态程序的能力已经达到每秒约700次,相当于一天承受 6000W的访问量,而服务器的负载也不算高。

③成本廉价

购买BIG-IP,netscaler等硬件负载均衡交换机需要大量RMB,然而nginx是开源的软件可以免费使用。

④配置文件非常简单

网络跟程序一样通俗易懂,即使非专业系统管理员也能看懂。

⑤支持Rewrite重写规则

能够根据域名,URL的不同,将HTTP请求分到不同的后端服务器上。

⑥内置的健康检查功能

如果nginxproxy 后端某台服务器挂了,也不会影响前端访问。

⑦节约带宽

支持GZIP压缩,可以添加浏览器本地缓存的header头。

⑧稳定性高

用于反向代理几乎不可能宕机。

⑨支持热部署

nginx它的启动多样化,并且可以数月不用重启,还可以在线对nginx版本升级。

额外的补充:除了nginx常用的其他web服务有哪些?

1.lighttpd。

2.tomcat。

3.IBM websphere。

4.microsoft IIS。

5.apache。

二nginx服务器的安装与配置

1.nginx的版本

旧的稳定版本为0.6 新的为0.7 0.8为测试开发版本

2.nginx的安装

既可以在linux可以在在Windows下。

3.nginx在linux下的安装。

下载相应的源码包

tar -zxvf nginx-0.7.65.tar.gz

./configure --prefix=/usr/local/nginx-0.7.65

make

make install

注意安装前必须安装pcre包。

我一般就加个路径 和开启监控模块,因为nginx的模块很灵活基本都可以安装在编辑。

下面介绍下congfiguer脚本支持的选项:

--help 帮助

--prefix=PATH 安装路径,默认为/usr/local/nginx

--sbin-path=PATH nginx可执行文件安装路径,只能安装时指定,默认为prefix/sbin/nginx

--conf-path=PATH 在没有指定-c选项下默认的nginx.conf的路径,默认prefix/conf/nginx.conf

--error-log-path=PATH 错误日志的路径,在莫有error_log指令下,默认prefix/logs/error.log

--pid-path=PATH 在nginx.conf没有pid指令下,默认的路径。默认prefix/logs/nginx.pid

--lock-path=PATH nginx.lock文件路径

--user=USER 设置工作进程的用户,默认nobody。

--group=GROUP 设置工作进程的组,默认nobody。

--builddir=DIR 指定编译目录,方便以后日后查询编译后的参数。

--with-rtsig_module 开启rtsig模块(实时信号)

--with-select_module 开启select模块

--without-select_module 关闭select模块

允许或者不允许select模式,如果config没有找到更合适的模式,比如epoll,kqueue,rtsig,select将是默认安装模式。

--with-poll_module 开启poll模块

--without-poll_module 关闭poll模块

允许或不允许poll模式,如果config没有找到更合适的模式,比如epoll,kqueue,rtsig,则可以开启poll块。

--with-ipv6 开启IPV6支持

--with-http_ssl_module 开启HTTPS支持。

--with-http_realip_module 开启 ngx_http_realip_module

--with-http_addition_module 开启 ngx_http_addition_module

--with-http_xslt_module 开启 ngx_http_xslt_module

--with-http_image_filter_module 开启 ngx_http_image_filter_module

--with-http_geoip_module 开启 ngx_http_geoip_module

--with-http_sub_module 开启 ngx_http_sub_module

--with-http_dav_module 开启 ngx_http_dav_module

--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_stub_status_module 开启 ngx_http_stub_status_module cacti监控页。

--without-http_charset_module 关闭 ngx_http_charset_module

--without-http_gzip_module 关闭 ngx_http_gzip_module

--without-http_ssi_module 关闭 ngx_http_ssi_module

--without-http_userid_module 关闭 ngx_http_userid_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

--without-http_proxy_module 关闭 ngx_http_proxy_module

--without-http_fastcgi_module 关闭 ngx_http_fastcgi_module

--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

--without-http_empty_gif_module 关闭 ngx_http_empty_gif_module

--without-http_browser_module 关闭 ngx_http_browser_module

--without-http_upstream_ip_hash_module 关闭 ngx_http_upstream_ip_hash_module

--with-http_perl_module 开启 ngx_http_perl_module

--with-perl_modules_path=PATH 指定perl模块的路径

--with-perl=PATH perl执行文件路径

--http-log-path=PATH 指定http默认访问日志的路径,日志切割。

--http-client-body-temp-path=PATH 指定http客户端缓存文件存放目录的路径。

--http-proxy-temp-path=PATH 指定http反向代理缓存文件存放目录的路径。

--http-fastcgi-temp-path=PATH 指定httpfastcgi缓存文件存放目录的路径。

--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 关闭 ngx_mail_pop3_module

--without-mail_imap_module 关闭 ngx_mail_imap_module

--without-mail_smtp_module 关闭 ngx_mail_smtp_module

--with-google_perftools_module 开启 ngx_google_perftools_module

--with-cpp_test_module 开启 ngx_cpp_test_module

--add-module=PATH 开启 an external module

--with-cc=PATH set path to C compiler

--with-cpp=PATH set path to C preprocessor

--with-cc-opt=OPTIONS set additional options for C compiler

--with-ld-opt=OPTIONS set additional options for linker

--with-cpu-opt=CPU build for specified CPU, the valid values:

pentium, pentiumpro, pentium3, pentium4,

athlon, opteron, sparc32, sparc64, ppc64

--without-pcre 关闭 --with-http_realip_module enable ngx_http_realip_module

--with-http_addition_module enable ngx_http_addition_module

--with-http_xslt_module enable ngx_http_xslt_module

--with-http_image_filter_module enable ngx_http_image_filter_module

--with-http_geoip_module enable ngx_http_geoip_module

--with-http_sub_module enable ngx_http_sub_module

--with-http_dav_module enable ngx_http_dav_module

--with-http_flv_module enable ngx_http_flv_module

--with-http_gzip_static_module enable ngx_http_gzip_static_module

--with-http_random_index_module enable ngx_http_random_index_module

--with-http_secure_link_module enable ngx_http_secure_link_module

--with-http_stub_status_module enable ngx_http_stub_status_module

--without-http_charset_module disable ngx_http_charset_module

--without-http_gzip_module disable ngx_http_gzip_module

--without-http_ssi_module disable ngx_http_ssi_module

--without-http_userid_module disable ngx_http_userid_module

--without-http_access_module disable ngx_http_access_module

--without-http_auth_basic_module disable ngx_http_auth_basic_module

--without-http_autoindex_module disable ngx_http_autoindex_module

--without-http_geo_module disable ngx_http_geo_module

--without-http_map_module disable ngx_http_map_module

--without-http_referer_module disable ngx_http_referer_module

--without-http_rewrite_module disable ngx_http_rewrite_module

--without-http_proxy_module disable ngx_http_proxy_module

--without-http_fastcgi_module disable ngx_http_fastcgi_module

--without-http_memcached_module disable ngx_http_memcached_module

--without-http_limit_zone_module disable ngx_http_limit_zone_module

--without-http_limit_req_module disable ngx_http_limit_req_module

--without-http_empty_gif_module disable ngx_http_empty_gif_module

--without-http_browser_module disable ngx_http_browser_module

--without-http_upstream_ip_hash_module

disable ngx_http_upstream_ip_hash_module

--with-http_perl_module enable ngx_http_perl_module

--with-perl_modules_path=PATH set path to the perl modules

--with-perl=PATH set path to the perl binary

--http-log-path=PATH set path to the http access log

--http-client-body-temp-path=PATH set path to the http client request body

temporary files

--http-proxy-temp-path=PATH set path to the http proxy temporary files

--http-fastcgi-temp-path=PATH set path to the http fastcgi temporary

files

--without-http disable HTTP server

--without-http-cache disable HTTP cache

--with-mail enable POP3/IMAP4/SMTP proxy module

--with-mail_ssl_module enable ngx_mail_ssl_module

--without-mail_pop3_module disable ngx_mail_pop3_module

--without-mail_imap_module disable ngx_mail_imap_module

--without-mail_smtp_module disable ngx_mail_smtp_module

--with-google_perftools_module enable ngx_google_perftools_module

--with-cpp_test_module enable ngx_cpp_test_module

--add-module=PATH enable an external module

--with-cc=PATH set path to C compiler

--with-cpp=PATH set path to C preprocessor

--with-cc-opt=OPTIONS set additional options for C compiler

--with-ld-opt=OPTIONS set additional options for linker

--with-cpu-opt=CPU build for specified CPU, the valid values:

pentium, pentiumpro, pentium3, pentium4,

athlon, opteron, sparc32, sparc64, ppc64

--without-pcre disable PCRE library usage

--with-pcre force PCRE library usage

--with-pcre=DIR set path to PCRE library sources

--with-pcre-opt=OPTIONS set additional options for PCRE building

--with-md5=DIR set path to md5 library sources

--with-md5-opt=OPTIONS set additional options for md5 building

--with-md5-asm use md5 assembler sources

--with-sha1=DIR set path to sha1 library sources

--with-sha1-opt=OPTIONS set additional options for sha1 building

--with-sha1-asm use sha1 assembler sources

--with-zlib=DIR 设置zlib 库的路径

--with-zlib-opt=OPTIONS 设置zlib库的额外选项

--with-zlib-asm=CPU zlib针对CPU的优化,合法值是:pentium ,pentiumpro。

--with-openssl=DIR 设置OpenSSL 库路径。

--with-openssl-opt=OPTIONS 设置OpenSSL库的额外选项。

--with-debug 开启调试日志
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  职场 休闲 nginx