首页 > 窍门 > 科技数码

Nginx如何配置url_hash转发方式 nginx转发配置详解

来源: 更新时间:2022-12-10 21:07:27
The Beginning

所需软件名称及版本:4Mx育儿早教网

pcre-8.02.tar.gz4Mx育儿早教网

nginx-0.7.58.tar.gz4Mx育儿早教网

Nginx_upstream_hash-0.3.1.tar.gz4Mx育儿早教网

1、安装pcre4Mx育儿早教网

tar -zxvf pcre-8.02.tar.gz4Mx育儿早教网

cd pcre-8.02/4Mx育儿早教网

./configure4Mx育儿早教网

make && make install4Mx育儿早教网

2、给nginx安装url_hash补丁4Mx育儿早教网

tar -zxvf nginx-0.7.58.tar.gz4Mx育儿早教网

tar -zxvf Nginx_upstream_hash-0.3.1.tar.gz4Mx育儿早教网

cd nginx-0.7.58/4Mx育儿早教网

patch -p0 < /var/tmp/loojoy/nginx_upstream_hash-0.3.1/nginx.patch4Mx育儿早教网

3、安装nginx4Mx育儿早教网

groupadd www4Mx育儿早教网

useradd www -g www4Mx育儿早教网

./configure --prefix=/usr/local/webserver/nginx4Mx育儿早教网

--user=www4Mx育儿早教网

--group=www4Mx育儿早教网

--add-module=/var/tmp/loojoy/nginx_upstream_hash-0.3.14Mx育儿早教网

--with-http_ssl_module4Mx育儿早教网

--with-http_stub_status_module4Mx育儿早教网

4、检查nginx生成的配置文件是否正确4Mx育儿早教网

/usr/local/webserver/nginx/sbin/nginx -t4Mx育儿早教网

5、启动nginx4Mx育儿早教网

若nginx.conf检查通过,则启动nginx。4Mx育儿早教网

/usr/local/webserver/nginx/sbin/nginx4Mx育儿早教网

6、查看端口804Mx育儿早教网

netstat -ant4Mx育儿早教网

7、通过浏览器访问:4Mx育儿早教网

http://your_nginx_server_ip/4Mx育儿早教网

若可以正常访问,则nginx安装成功。4Mx育儿早教网

8、修改nginx的配置文件如下:4Mx育儿早教网

-------------------url_hash转发方式nginx.conf--------------------4Mx育儿早教网

user www www4Mx育儿早教网

worker_processes 104Mx育儿早教网

error_log logs/error.log4Mx育儿早教网

#error_log logs/error.log notice4Mx育儿早教网

#error_log logs/error.log info4Mx育儿早教网

#pid logs/nginx.pid4Mx育儿早教网

worker_rlimit_nofile 512004Mx育儿早教网

events4Mx育儿早教网

{4Mx育儿早教网

use epoll4Mx育儿早教网

worker_connections 512004Mx育儿早教网

}4Mx育儿早教网

http4Mx育儿早教网

{4Mx育儿早教网

include mime.types4Mx育儿早教网

default_type application/octet-stream4Mx育儿早教网

keepalive_timeout 1204Mx育儿早教网

tcp_nodelay on4Mx育儿早教网

upstream your.website.name{4Mx育儿早教网

server your.tomcat.server.ip1:80804Mx育儿早教网

server your.tomcat.server.ip1:80804Mx育儿早教网

hash $request_uri4Mx育儿早教网

}4Mx育儿早教网

server4Mx育儿早教网

{4Mx育儿早教网

listen 804Mx育儿早教网

server_name your.website.name4Mx育儿早教网

location / {4Mx育儿早教网

proxy_pass http://your.website.name4Mx育儿早教网

proxy_set_header Host $host4Mx育儿早教网

proxy_set_header X-Real-IP $remote_addr4Mx育儿早教网

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for4Mx育儿早教网

}4Mx育儿早教网

log_format www_gjw_com '$remote_addr - $remote_user [$time_local] $request '4Mx育儿早教网

'"$status" $body_bytes_sent "$http_referer" '4Mx育儿早教网

'"$http_user_agent" "$http_x_forwarded_for"'4Mx育儿早教网

#access_log /data1/logs/www.log www_gjw_com4Mx育儿早教网

location /nginx_status {4Mx育儿早教网

stub_status on4Mx育儿早教网

access_log off4Mx育儿早教网

}4Mx育儿早教网

}4Mx育儿早教网

}4Mx育儿早教网

-------------------[E]url_hash转发方式nginx.conf[E]--------------------4Mx育儿早教网

9、添加nginx启动、关闭、重启脚本4Mx育儿早教网

-------------------[S]url_hash转发方式nginx启动、关闭脚本[S]--------------------4Mx育儿早教网

#!/bin/sh4Mx育儿早教网

CWD=`pwd`4Mx育儿早教网

case $1 in4Mx育儿早教网

start)4Mx育儿早教网

/usr/local/webserver/nginx/sbin/nginx4Mx育儿早教网

;4Mx育儿早教网

stop)4Mx育儿早教网

kill -2 `ps -ef|grep "/usr/local/webserver/nginx/sbin/nginx"|grep -v "grep"|awk '{print $2}' `4Mx育儿早教网

;4Mx育儿早教网

restart)4Mx育儿早教网

cd "$CMD"4Mx育儿早教网

$0 stop4Mx育儿早教网

$0 start4Mx育儿早教网

;4Mx育儿早教网

*)4Mx育儿早教网

echo $"Usage: $0 {start|stop|restart}"4Mx育儿早教网

exit 14Mx育儿早教网

esac4Mx育儿早教网

exit 04Mx育儿早教网

-------------------[E]url_hash转发方式nginx启动、关闭脚本[E]--------------------4Mx育儿早教网

更改该文件权限4Mx育儿早教网

chmod u+x nginx.sh4Mx育儿早教网

启动 nginx ./nginx.sh start4Mx育儿早教网

重启 nginx ./nginx.sh restart4Mx育儿早教网

关闭 nginx ./nginx.sh stop4Mx育儿早教网

THE END

TAG:方式  脚本  重启  

猜你喜欢

相关文章