Nginx sticky module implements session stickiness

Source: Internet
Author: User

Nginx sticky module implements session stickiness

Nginx sticky module implements session stickiness

Note: nginx is installed in the system.
 
1. Download and decompress the nginx sticky module.
# Cd/usr/local/src
# Wget http://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.1.tar.gz
# Tar-zxvf nginx-sticky-module-1.1.tar.gz

2. Check the compilation parameters of the existing nginx and re-compile with the sticky module parameters.
#/Usr/local/nginx/sbin/nginx-V
Nginx version: nginx/1.3.14
Built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
Tls sni support disabled
Configure arguments: -- prefix =/usr/local/nginx -- user = nobody -- group = nobody -- with-select_module -- with-poll_module -- with-file-aio -- with-http_ssl_module -- with-http_realip_module -- with-http_gzip_static_module -- with-http_secure_link_module -- with-http_sub_module -- with-http_stub_status_module -- add-module =/root/nginx-http-concat/

Disable nginx and add the sticky module to re-compile nginx (we recommend that you back up the configuration file first)
# Service nginx stop
# Cd/usr/local/src/nginx-1.3.14
#. /Configure -- prefix =/usr/local/nginx -- user = nobody -- group = nobody -- with-select_module -- with-poll_module -- with-file-aio -- with-http_ssl_module -- with-http_realip_module -- with-http_gzip_static_module -- with-http_secure_link_module -- with-http_sub_module -- with-http_stub_status_module -- add-module =/root/nginx-http-concat/-- add-module =/usr/local/src/nginx-sticky-module-1.1
# Make & make install

3. modify the configuration file and add sticky parameters.
Add parameters (in red) at a location similar to the following)
Vi upstream. conf
Upstream bkjia.com
{
Sticky; --- sticky
Server192.168.1.17: 9082 weight = 5 max_fails = 2 fail_timeout = 30 s;
Server192.168.1.81: 9082 weight = 5 max_fails = 2 fail_timeout = 30 s;
}


# Vi web. conf
Server {
Listen 9082;
Server_name * .bkjia.com;
Access_log/data/logs/bkjia.com access_log;
Error_log/data/logs/bkjia.com. errorlog;
Set $ proxy_pass bkjia.com;

Location /{
Root html;
Index index.html index.htm;
Proxy_set_header Host $ host: $ server_port;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_pass http://bkjia.com;
Add_headerCache-Control no-store;

}

4. Start nginx and perform webpage testing.
#/Usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx. conf
Or
# Service nginx start

For more Nginx tutorials, see the following:

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.