自编译安装nginx
1. 下载nginx,并解压
http://nginx.org/
2. 下载health check模块
git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
2.1 下载sticky session模块
from:https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/overview
git clone https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng.git
3. 安装依赖模块包,配置预编译环境
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
建立nginx 组
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx
id nginx
zlib:nginx提供gzip模块,需要zlib库支持
openssl:nginx提供ssl功能
pcre:支持地址重写rewrite功能
4. 进入nginx解压目录,开始编译
*注意最后一个add-module,是编译加上health check模块
./configure \
--prefix=/opt/apps_install \
--sbin-path=/opt/apps_install/nginx-1.10.2/sbin/nginx \
--conf-path=/opt/conf/nginx/nginx.conf \
--error-log-path=/opt/logs/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--http-log-path=/opt/logs/nginx/access.log \
--http-client-body-temp-path=/opt/apps_install/nginx-1.10.2/client_body_temp \
--http-proxy-temp-path=/opt/apps_install/nginx-1.10.2/proxy_temp \
--http-fastcgi-temp-path=/opt/apps_install/nginx-1.10.2/fastcgi_temp \
--http-uwsgi-temp-path=/opt/apps_install/nginx-1.10.2/uwsgi_temp \
--http-scgi-temp-path=/opt/apps_install/nginx-1.10.2/scgi_temp \
--http-uwsgi-temp-path=/opt/apps_install/nginx-1.10.2/uwsgi_temp \
--http-scgi-temp-path=/opt/apps_install/nginx-1.10.2/scgi_temp \
--with-http_stub_status_module \
--add-module=/home/nginx-1.10.2/nginx_upstream_check_module \
--add-module=/home/nginx-1.10.2/nginx-sticky-module-ng
5、make && make install
6、ln -s /opt/apps_nginx/nginx-1.10.2/sbin/nginx /usr/bin/nginx
6.1 nginx -V
7、使用sticky session
将一下内容放置在upstream模块里
sticky [name=route] [domain=.foo.bar] [path=/] [expires=1h]
[hash=index|md5|sha1] [no_fallback] [secure] [httponly];
8、使用healthcheck
10、常见问题
在配置nginx提示如下错误时:
[emerg]: getpwnam(“nginx”) failed
解决方案:
nginx用户没有创建和打开,执行3中的创建nginx用户和给予权限即可