所需软件名称及版本:
pcre-8.02.tar.gz
nginx-0.7.58.tar.gz
Nginx_upstream_hash-0.3.1.tar.gz
1、安装pcre
tar -zxvf pcre-8.02.tar.gz
cd pcre-8.02/
./configure
make && make install
2、给nginx安装url_hash补丁
tar -zxvf nginx-0.7.58.tar.gz
tar -zxvf Nginx_upstream_hash-0.3.1.tar.gz
cd nginx-0.7.58/
patch -p0 < /var/tmp/loojoy/nginx_upstream_hash-0.3.1/nginx.patch
3、安装nginx
groupadd www
useradd www -g www
./configure --prefix=/usr/local/webserver/nginx \
--user=www \
--group=www \
--add-module=/var/tmp/loojoy/nginx_upstream_hash-0.3.1 \
--with-http_ssl_module \
--with-http_stub_status_module
4、检查nginx生成的配置文件是否正确
/usr/local/webserver/nginx/sbin/nginx -t
5、启动nginx
若nginx.conf检查通过,则启动nginx。
/usr/local/webserver/nginx/sbin/nginx
6、查看端口80
netstat -ant
7、通过浏览器访问:
http://your_nginx_server_ip/
若可以正常访问,则nginx安装成功。
8、修改nginx的配置文件如下:
-------------------[S]url_hash转发方式nginx.conf[S]--------------------
user www www;
worker_processes 10;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
keepalive_timeout 120;
tcp_nodelay on;
upstream your.website.name{
server your.tomcat.server.ip1:8080 ;
server your.tomcat.server.ip1:8080 ;
hash $request_uri;
}
server
{
listen 80;
server_name your.website.name;
location / {
proxy_pass http://your.website.name;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
log_format www_gjw_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log /data1/logs/www.log www_gjw_com;
location /nginx_status {
stub_status on;
access_log off;
}
}
}
-------------------[E]url_hash转发方式nginx.conf[E]--------------------
9、添加nginx启动、关闭、重启脚本
-------------------[S]url_hash转发方式nginx启动、关闭脚本[S]--------------------
#!/bin/sh
CWD=`pwd`
case $1 in
start)
/usr/local/webserver/nginx/sbin/nginx
;;
stop)
kill -2 `ps -ef|grep "/usr/local/webserver/nginx/sbin/nginx"|grep -v "grep"|awk '{print $2}' `
;;
restart)
cd "$CMD"
$0 stop
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
-------------------[E]url_hash转发方式nginx启动、关闭脚本[E]--------------------
更改该文件权限
chmod u+x nginx.sh
启动 nginx ./nginx.sh start
重启 nginx ./nginx.sh restart
关闭 nginx ./nginx.sh stop
分享到:
相关推荐
Nginx如何配置url_hash转发方式.docx
url_hash 是nginx的第三方模块,nginx本身不支持,需要打patch . Url_hash 你nginx在做负载均衡的时候。把转发的URL 以hash的形式保存。这样可以保证同一个URL始终 分给同一个real server,来提高访问速度。
NGINX第三方模块:nginx_upstream_hash-0.3.1.tar.gz。
NGINX第三方模块:nginx_upstream_hash-0.3.2版本。。。
Nginx upstream urlhash url hash 反向代理 Nginx upstream urlhash url hash 反向代理
在此记录下Nginx服务器nginx.conf的配置文件说明, 部分注释收集与网络. #运行用户 user www-data; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 error_log /var/log/...
nginx优化之request_time 和upstream_response_time差别笔者在根据nginx的accesslog中$request_time
包含yamdi-1.9.tar.gz nginx_mod_h264_streaming-2.2.7.tar.gz nginx-1.8.1
nginx_tcp_proxy_module-master.zip
海康摄像头实时预览通过nginx反向代理
Nginx 配置TCP代理转发 使用Nginx 新版的 stream方式,实现TCP/UDP代理转发。
官方nginx 镜像不带主动健康,本镜像将 nginx_upstream_check健康检查 打包到了镜像中。
51CTO下载-nginx完整配置手册_v1.pdf
Nginx所需环境的安装,及nginx安装,nginx相关功能开启,后端节点健康检查插件安装,静态资源缓存插件,缩略图插件安装等。
nginx判读user_agent并转发请求配置文件
nginx配置优化+负载均衡+动静分离详解
linux nginx nginx_upstream_jvm_route
根据nginx源码进行ip_hash四段计算,实现负载均衡
nginx 基础配置与参数说明(中文备注)