In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to solve the Nginx+resin session problem, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Test environment:
Nginx + resin is installed on the server1 server
Only resin is installed on the server2 server
Server1 IP address: 192.168.6.121
Server2 IP address: 192.168.6.162
Installation steps:
1. Install and configure nginx + nginx_upstream_jvm_route on server1
Shell $> wget-c http://sysoev.ru/nginx/nginx-0.7.61.tar.gz
Shell $> svn checkout http://nginx-upstream-jvm-route.googlecode.com/svn/trunk/ nginx-upstream-jvm-route-read-only
Shell $> tar zxvf nginx-0.7.61
Shell $> cd nginx-0.7.61
Shell $> patch-p0
< ../nginx-upstream-jvm-route-read-only/jvm_route.patch shell $>Useradd www
Shell $>. / configure-- user=www-- group=www-- prefix=/usr/local/webserver/nginx-- with-http_stub_status_module-- with-http_ssl_module-- add-module=/root/nginx-upstream-jvm-route-read-only
Shell $> make
Shell $> make install
two。 Install resin on two machines
# modify environment variable #
Shell $> vim / etc/profile
# add the following # under umask 022
JAVA_HOME=/usr/lib/jvm/java-6-sun
Export JAVA_HOME
JRE_HOME= "${JAVA_HOME}" / jre
Export JRE_HOME
CLASSPATH=.: "${JAVA_HOME}" / lib/tools.jar: "${JAVA_HOME}" / lib/dt.jar$ {RESIN_HOME} "/ lib/resin.jar:" ${CLASSPATH}
Export CLASSPATH
RESIN_HOME=/usr/local/resin
Export RESIN_HOME
PATH= "${JAVA_HOME}" / bin: "${PATH}"
Export PATH
Shell $> wget-c http://www.caucho.com/download/resin-3.1.9.tar.gz
Shell $> tar zxvf resin-3.1.9.tar.gz
Shell $> cd resin-3.1.9
Shell $>. / configure-- prefix=/usr/local/resin
Shell $> make
Shell $> make install
3. Configure resin for two machines
Shell $> cd / usr/local/resin
Shell $> cd conf
Shell $> vim resin.conf
# # find
# # comment out
# # find
# # replace with
Shell $> cd / usr/local/resin/webapps/ROOT/
Shell $> mv index.jsp index.jsp.bak
Shell $> vim index.jsp
# # enter the following
one hundred and twenty one
# restart resin service #
# server1 server #
Shell $> / usr/local/resin/bin/httpd.sh-server a start
# Note if the environment variable is not modified, an error will be reported.
# server2 server #
Shell $> / usr/local/resin/bin/httpd.sh-server b start
# Note that the server2 server only starts server_id b #
4. Integrate ngxin resin
Shell $> cd / usr/local/nginx/conf
Shell $> mv nginx.conf nginx.bak
Shell $> vim nginx.conf
# # the following is configuration #
User www www
Worker_processes 4
Error_log logs/nginx_error.log crit
Pid / usr/local/nginx/nginx.pid
# Specifies the value for maximum file descriptors that can be opened by this process.
Worker_rlimit_nofile 51200
Events
{
Use epoll
Worker_connections 2048
}
Http
{
Upstream backend {
Server 192.168.6.121:8080 srun_id=a
# here srun_id=a corresponds to server id= "a" in server1 resin configuration
Server 192.168.6.162:8081 srun_id=b
# here srun_id=b corresponds to server id= "b" in server2 resin configuration
Jvm_route $cookie_JSESSIONID | sessionid
}
Include mime.types
Default_type application/octet-stream
# charset gb2312
Charset UTF-8
Server_names_hash_bucket_size 128
Client_header_buffer_size 32k
Large_client_header_buffers 4 32k
Client_max_body_size 20m
Limit_rate 1024k
Sendfile on
Tcp_nopush on
Keepalive_timeout 60
Tcp_nodelay on
Fastcgi_connect_timeout 300
Fastcgi_send_timeout 300
Fastcgi_read_timeout 300
Fastcgi_buffer_size 64k
Fastcgi_buffers 4 64k
Fastcgi_busy_buffers_size 128k
Fastcgi_temp_file_write_size 128k
Gzip on
# gzip_min_length 1k
Gzip_buffers 4 16k
Gzip_http_version 1.0
Gzip_comp_level 2
Gzip_types text/plain application/x-javascript text/css application/xml
Gzip_vary on
# limit_zone crawler $binary_remote_addr 10m
Server
{
Listen 80
Server_name 192.168.6.121
Index index.html index.htm index.jsp
Root / var/www
Location ~. *\ .jsp$
{
Proxy_pass http://backend;
Proxy_redirect off
Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for
Proxy_set_header X-Real-IP $remote_addr
Proxy_set_header Host $http_host
}
Location ~. *\. (gif | jpg | jpeg | png | bmp | swf) $
{
Expires 30d
}
Location. *\. (js | css)? $
{
Expires 1h
}
Location / stu {
Stub_status on
Access_log off
}
Log_format access'$remote_addr-$remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" $http_x_forwarded_for'
# access_log off
}
}
5. Test, open the browser, type http://192.168.6.121/index.jsp
Session shows that aXXXXX accesses 121server, that is, server1. Because it is the first time to visit, Cookie does not get it. Refresh it to see if he will poll to access 162server2.
In order to test, I opened the Firefox browser again (because of session and cookie problems, so re-open other browsers). After entering the URL, it shows 162,The session value starts with bXXX, and after refreshing N times, it is still 162Firefox 2 server! If you have any questions during the test, you can have a nginx configuration file.
Remove srun_id=a srun_id=b, and then visit, you will know that the page is polling access!
The patch I uploaded was unzipped on linux, because 51cto does not support gz format, so I changed my suffix to execute it on linux.
Shell $> tar zxvf nginx-upstream-jvm-route-read-only.rar
Just do it!
The workaround for tomcat is available on README:
1.For resin
Upstream backend {
Server 192.168.0.100 srun_id=a
Server 192.168.0.101 srun_id=b
Server 192.168.0.102 srun_id=c
Server 192.168.0.103 srun_id=d
Jvm_route $cookie_JSESSIONID | sessionid
}
2.For tomcat
Upstream backend {
Server 192.168.0.100 srun_id=a
Server 192.168.0.101 srun_id=b
Server 192.168.0.102 srun_id=c
Server 192.168.0.103 srun_id=d
Jvm_route $cookie_JSESSIONID | sessionid reverse
}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.