edit-icon download-icon

Configure cookie in the backend server

Last Updated: Dec 05, 2017

Server Load Balancer provides session persistence function. With session persistence enabled, Server Load Balancer can distribute requests from the same client to the same backend server during the session period.

For layer-4 listeners, session persistence is based on the IP address. The listener of Server Load Balancer forwards requests from the same IP address to the same backend server.

For layer-7 listeners, session persistence is based on cookies. If you choose the Rewrite Cookie method, you can set the Cookie Name as name, and set the key of vip.a.com‘s cookie as name on the backend server.

cookie

Follow the instructions in this section to set cookies on a backend server.

Apache

  1. Open the httpd.conf file and make sure that the following line is not commented.

    LoadModule usertrack_module modules/mod_usertrack.so

  2. Add the following configurations in the VirtualHost file.

    1. CookieName name
    2. CookieExpires "1 days"
    3. CookieStyle Cookie
    4. CookieTracking on

Nginx

Configure the configuration file as follows.

  1. server {
  2. listen 8080;
  3. server_name wqwq.example.com;
  4. location / {
  5. add_header Set-Cookie name=xxxx;
  6. root html;
  7. index index.html index.htm;
  8. }
  9. }

Lighttpd

Configure the configuration file as follows.

  1. server.modules = ( "mod_setenv" )
  2. $HTTP["host"] == "test.example.com" {
  3. server.document-root = "/var/www/html/"
  4. setenv.add-response-header = ( "Set-Cookie" => "name=XXXXXX" )
  5. }
Thank you! We've received your feedback.