Nginx ("engine x") 是一个高性能的 HTTP 和
反向代理 服务器,也是一个 IMAP/POP3/SMTP
服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将
源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,
并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:新浪、
网易、腾讯等。
nginx由于功能强大,高负载低内存消耗,支持高并发,稳定等性能已经被越来越多的公司作为web解决方案。
我自己的总结下nginx的用途
1.最主要的还是用作web服务器,以快速稳定而闻名,完全可以单挑http了。
2.负载均衡器,作为优秀的七层负载均衡器,能实现对应用层的负载和转移,包括对地址的重定向,url重写等强大功能,而且作为负载均衡器配,占用网络资源相当小(配置比起lvs简单好几个数量级),加上配合keepalived等可以免除单点故障实现高可用。
3.其实他还是一款优秀的电子邮件代理服务器和反向代理服务器(翻墙技术。。)只是在国内用的少。
4.在前端完全可以全部采用nginx实现部署。
首先来看下nginx安装吧,安装也是相当的简单。
进官网下载最新稳定版 http://nginx.org/download/nginx-1.8.0.tar.gz
操作系统 CENTOS6.5
下载软件 wget http://nginx.org/download/nginx-1.8.0.tar.gz
只有813k大小
解压 tar -xvf nginx-1.8.0.tar.gz
点击(此处)折叠或打开
- ./configure --help
-
- --help print this message
-
- --prefix=PATH set installation prefix
- --sbin-path=PATH set nginx binary pathname
- --conf-path=PATH set nginx.conf pathname
- --error-log-path=PATH set error log pathname
- --pid-path=PATH set nginx.pid pathname
- --lock-path=PATH set nginx.lock pathname
-
- --user=USER set non-privileged user for
- worker processes
- --group=GROUP set non-privileged group for
- worker processes
-
- --build=NAME set build name
- --builddir=DIR set build directory
-
- --with-rtsig_module enable rtsig module
- --with-select_module enable select module
- --without-select_module disable select module
- --with-poll_module enable poll module
- --without-poll_module disable poll module
-
- --with-threads enable thread pool support
-
- --with-file-aio enable file AIO support
- --with-ipv6 enable IPv6 support
-
- --with-http_ssl_module enable ngx_http_ssl_module
- --with-http_spdy_module enable ngx_http_spdy_module
- --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_mp4_module enable ngx_http_mp4_module
- --with-http_gunzip_module enable ngx_http_gunzip_module
- --with-http_gzip_static_module enable ngx_http_gzip_static_module
- --with-http_auth_request_module enable ngx_http_auth_request_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_degradation_module enable ngx_http_degradation_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_split_clients_module disable ngx_http_split_clients_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_uwsgi_module disable ngx_http_uwsgi_module
- --without-http_scgi_module disable ngx_http_scgi_module
- --without-http_memcached_module disable ngx_http_memcached_module
- --without-http_limit_conn_module disable ngx_http_limit_conn_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_hash_module
- disable ngx_http_upstream_hash_module
- --without-http_upstream_ip_hash_module
- disable ngx_http_upstream_ip_hash_module
- --without-http_upstream_least_conn_module
- disable ngx_http_upstream_least_conn_module
- --without-http_upstream_keepalive_module
- disable ngx_http_upstream_keepalive_module
-
- --with-http_perl_module enable ngx_http_perl_module
- --with-perl_modules_path=PATH set Perl modules path
- --with-perl=PATH set perl binary pathname
-
- --http-log-path=PATH set http access log pathname
- --http-client-body-temp-path=PATH set path to store
- http client request body temporary files
- --http-proxy-temp-path=PATH set path to store
- http proxy temporary files
- --http-fastcgi-temp-path=PATH set path to store
- http fastcgi temporary files
- --http-uwsgi-temp-path=PATH set path to store
- http uwsgi temporary files
- --http-scgi-temp-path=PATH set path to store
- http scgi 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 C compiler pathname
- --with-cpp=PATH set C preprocessor pathname
- --with-cc-opt=OPTIONS set additional C compiler options
- --with-ld-opt=OPTIONS set additional linker options
- --with-cpu-opt=CPU build for the specified CPU, 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 build options for PCRE
- --with-pcre-jit build PCRE with JIT compilation support
-
- --with-md5=DIR set path to md5 library sources
- --with-md5-opt=OPTIONS set additional build options for md5
- --with-md5-asm use md5 assembler sources
-
- --with-sha1=DIR set path to sha1 library sources
- --with-sha1-opt=OPTIONS set additional build options for sha1
- --with-sha1-asm use sha1 assembler sources
-
- --with-zlib=DIR set path to zlib library sources
- --with-zlib-opt=OPTIONS set additional build options for zlib
- --with-zlib-asm=CPU use zlib assembler sources optimized
- for the specified CPU, valid values:
- pentium, pentiumpro
-
- --with-libatomic force libatomic_ops library usage
- --with-libatomic=DIR set path to libatomic_ops library sources
-
- --with-openssl=DIR set path to OpenSSL library sources
- --with-openssl-opt=OPTIONS set additional build options for OpenSSL
-
- --with-debug enable debug logging
./configure --prefix=/usr/local/nginx/
由于我是测试用,具体的模块自己选择,我就用最简单的默认模式了。。。
./configure: error: the HTTP rewrite module requires the PCRE library.
报错。。。。找不到pcre依赖库
使用yum install pcre-devel -y 安装,如果源码安装的要指定pcre目录
./configure: error: the HTTP rewrite module requires the PCRE library.
报错。。。。找不到pcre依赖库
这样缺少什么就安装什么,另外我安装的时候要手动指定下zlib库,rpm -ql zlib 查看所在目录
编译成功了就是make && make install 了
nginx目录:client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
主目录是sbin ,logs,html,conf。
sbin目录下是nginx的二进制程序,用来启动nginx
logs下存放nginx一些相关目录,可以有配置文件指定
html 下存放具体的页面文件,类似tomcat的webapps目录,可以由配置文件指定。
conf目录下是配置文件
启动nginx /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 启动时指定配置文件
sbin目录下是nginx的二进制程序,用来启动nginx
logs下存放nginx一些相关目录,可以有配置文件指定
html 下存放具体的页面文件,类似tomcat的webapps目录,可以由配置文件指定。
conf目录下是配置文件
查看端口netstat -tunlp
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2840/nginx
80端口启动成功
到此nginx成功安装。