tar -zxvf nginx-1.9.10.tar.gz
groupadd nginx
useradd -g nginx -s /sbin/nologin nginx
mkdir -p /var/tmp/nginx/client/
mkdir -p /usr/local/nginx
cd nginx-1.9.0
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --http-client-body-temp-path=/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 --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --add-module=../nginx-upsync-module-master
make && make install
./configure: error: SSL modules require the OpenSSL library.
yum -y install openssl openssl-devel
##动态去consul 获取注册的真实反向代理地址
upstream itmayiedu{
server 127.0.0.1:11111;
upsync 192.168.212.134:8500/v1/kv/upstreams/itmayiedu upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://senge.com;
index index.html index.htm;
}
}
upsync:指令指定从consul哪个路径拉取上游服务器配置;
upsync_timeout:配置从consul拉取上游服务器配置的超时时间;
upsync_interval:配置从consul拉取上游服务器配置的间隔时间;
upsync_type:指定使用consul配置服务器;
strong_dependency:配置nginx在启动时是否强制依赖配置服务器,如果配置为on,则拉取配置失败时nginx启动同样失败。
upsync_dump_path:指定从consul拉取的上游服务器后持久化到的位置,这样即使consul服务器出问题了,本地还有一个备份。
mkdir /usr/local/nginx/conf/servers/
upsync_dump_path指定从consul拉取的上游服务器后持久化到的位置,这样即使consul服务器出问题了,本地还有一个备份。
临时关闭防火墙systemctl stop firewalld
./consul agent -dev -ui -node=consul-dev -client=192.168.212.131
curl -X PUT http://192.168.212.134:8500/v1/kv/upstreams/itmayiedu/192.168.212.1:8081
curl -X PUT http://192.168.212.134:8500/v1/kv/upstreams/itmayiedu/192.168.212.1:8081
http://192.168.212.134:8500/v1/kv/upstreams/itmayiedu/192.168.212.1:8081
http://192.168.212.134:8500/v1/kv/upstreams/itmayiedu/192.168.212.1:8081