第一步:从http://nginx.org/download/...http://nginx.org/download/nginx-1.5.9.tar.gz直接在Linux上用命令下载)第二步:解压tar-zxvfnginx-1.5.9.tar.gz第三步:为了后续准备,我们额外下载2个插件模块:nginx_upstream_check_module-0.3.0.tar.gz(查看后台服务器状态)、nginx-goodies-nginx-sticky-module-ng-bd312d586752.tar.gz(建议在/usr/local/src下解压后重命名目录为nginx-sticky-module-ng-1.2.5)后端做负载均衡解决sessionsticky问题(结合upstream_check模块需要单独打补丁,请参考nginx负载均衡配置实战)。nginx-goodies-nginx-sticky-module-ng-bd312d586752.tar.gz作用:后端负载均衡,解决会话粘性问题https://github.com/yaoweibin/nginx_upstream_check_module/releasesnginx_upstream_check_module-0.3.0.tar.gz作用:查看后台服务器状态https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/downloads请注意插件与nginx的版本兼容。一般插件越新越好,nginx不用追新。稳定第一。nginx-1.4.7、nginx-sticky-module-1.1、nginx_upstream_check_module-0.2.0,这个组合也没有问题。sticky-1.1和nginx-1.6版本由于更新跟不上编译报错。(可以直接使用Tengine,默认就包了这些模块)安装配置一:./configure--prefix=/usr/local/nginx-1.6--with-pcre=../pcre-8.31\>--with-http_stub_status_module--with-http_ssl_module\>--with-http_gzip_static_module--with-http_realip_module\>--add-module=../nginx_upstream_check_module-0.3.0安装配置二:./configure\>--prefix=/usr\>--sbin-path=/usr/sbin/nginx\>--conf-path=/etc/nginx/nginx.conf\>--error-log-path=/var/log/nginx/error.log\>--http-log-path=/var/log/nginx/access.log\>--pid-path=/var/run/nginx/nginx.pid\>--lock-path=/var/lock/nginx.lock\>--user=nginx\>--group=nginx\>--with-http_ssl_module\>--with-http_stub_status_module\>--with-http_gzip_static_module\>--http-client-body-temp-路径=/var/tmp/nginx/client/\>--http-proxy-temp-path=/var/tmp/nginx/proxy/\>--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/\>--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\>--with-pcre=../pcre-7.8&g吨;--with-zlib=../zlib-1.2.3常用编译选项解释了nginx的大部分常用模块。编译时./configure--help,默认安装--without开头的--prefix=PATH:指定nginx安装目录。默认/usr/local/nginx--conf-path=PATH:设置nginx.conf配置文件的路径。nginx允许通过命令行上的-c选项以不同的配置文件启动。默认是prefix/conf/nginx.conf--user=name:设置nginxworker进程的用户。安装完成后,您可以随时更改nginx.conf配置文件中的user指令。默认用户名是nobody。--group=name类似于--with-pcre:设置PCRE库的源代码路径。如果已经通过yum安装,使用--with-pcre自动查找库文件。使用--with-pcre=PATH时,需要从PCRE网站下载pcre库(4.4-8.30版本)的源码并解压。剩下的由Nginx的./configure和make完成。Perl正则表达式用于location指令和ngx_http_rewrite_module模块。--with-zlib=PATH:指定zlib(版本1.1.3–1.2.5)源代码提取目录。网络传输压缩模块ngx_http_gzip_module需要zlib,默认启用。--with-http_ssl_module:使用https协议模块。默认情况下,不构建此模块。前提是已经安装了openssl和openssl-devel--with-http_stub_status_module:用来监控Nginx的当前状态--with-http_realip_module:这个模块允许我们改变客户端请求头中的客户端IP地址值(比如asX-Real-IPorX-Forwarded-For),意思是让后台服务器记录原来客户端的IP地址--add-module=PATH:添加第三方外部模块,比如nginx-sticky-module-ng或缓存模块。每增加一个新模块,都需要重新编译(Tengine增加新模块不需要重新编译)第四步:make编译(make的过程就是将各种语言编写的源代码文件转换成可执行文件文件和各种库文件)makeinstall安装(makeinstall就是把这些编译好的可执行文件和库文件复制到合适的地方)第五步:启动和关闭nginx,检查配置文件是否正确$/usr/local/nginx-1.6/sbin/nginx-t$./sbin/nginx-V#可以看到启动和关闭的编译选项$./sbin/nginx#默认配置文件conf/nginx.conf,-c指定$./sbin/nginx-sstoporpkillnginxrestart,不会改变启动时指定的配置文件$./sbin/nginx-sreloadorkill-HUPcat/usr/local/nginx-1.6/logs/nginx.pid当然,nginx也可以作为系统服务来管理,下载nginx到/etc/init.d/,修改里面的路径,赋予可执行权限。关注公众号获取海量视频
