Php + nginx Server Load balancer and session configuration difficulties are worth further research.
Source: Internet
Author: User
Php + nginx Server Load balancer and session configuration difficulties are worth further research. -- Linux general technology-Linux technology and application information. For details, refer to the following section. [I = s] This post was last edited at, 123498296
The server is achieved through session NFS sharing! The configuration of session NFS sharing is as follows:
First, modify the session. save_path option of php. ini as follows:
Session. save_path = "2;/tmp/php_sess" (remove the semicolon)
The session is stored in the "/tmp/php_sess" directory and divided into two sub-directories. Each sub-directory has 16 sub-directories.
2. assume that the main directory of php is/usr/local/server/php/, create a file/usr/local/server/php/include/php/ext/session/mod_files.sh, the content is as follows:
#! /Bin/sh
# NAME
# Mod_files.sh-Update of the php-source/ext/session/mod_files.sh
#
# SYNOPSIS
# Mod_files.sh basedir depth [numberofsubdirs]
#
# DESCRIPTION
# This script creates the directories tree used by php to store the session files
# (See php. ini-'session. save_path 'option)
#
# Example: if you want php to store the session files in a directory tree
# Of 3 levels of depth containing 32 directories in each directory,
# First, put the setting bellow in the php. ini file:
#
# Session. save_path = "3;/tmp/session"
#
# Now create the basedir directory: 'mkdir/tmp/session'
#
# Then, call this scrip with the following arguments:
#
#./Mod_files.sh./mod_files.sh/tmp/session 3 32
If test "$2" = ""; then
Echo "usage: $0 basedir depth [numberofsubdirs]"
Echo "numberofsubdirs: if unset, defaults to 16. if 32, 32 subdirs, if 64, 64 subdirs ."
Exit 1
Fi
If test "$2" = "0"; then
Exit 0
Fi
Hash_chars = "0 1 2 3 4 5 6 7 8 9 a B c d e f"
If [! -Z $3]; then
If test "$3"-a "$3"-eq "32"; then
Hash_chars = "$ hash_chars g h I j k l m n o p q r s t u v"
If test "$3"-eq "64"; then
Hash_chars = "$ hash_chars w x y z a B c d e f g h I J K L M N O P Q R S T U V W X Y Z -,"
Fi
Fi
Fi
For I in $ hash_chars; do
Newpath = "$1/$ I"
Mkdir $ newpath | exit 1
Sh $0 $ newpath 'expr $2-1' $3
Done
3. After being set to executable, run the following command to create a hash directory:
4. Now, we can set up NFS sharing. Assume that there are three hosts with ip addresses 192.168.0.1 (host name svr1), 192.168.0.2 (host name svr2), and 192.168.0.3 (host name svr3). Now let 192.168.0.1 provide NFS sharing service, configure/etc/exports and add the following content:
/Tmp/php_sess/svr * (rw, no_root_squash)
5. Restart the nfs service to provide NFS sharing for the other two hosts.
Run the following commands on svr2 and svr3 to mount NFS:
# Mkdir/tmp/php_sess
# Mount svr1:/tmp/php_sess
The session NFS sharing is completed according to the above configuration, but the problem arises,
My PHP script on server A is as follows:
Sei. php (file name)
Then use the PHP script in service B as follows:
Sei. php (file name)
Session_start ();
$ _ SESSION ['id'];
Echo $ _ SESSION ['id'];
?>
Test: Service A can display ABC normally, but service B cannot obtain the session accessed by service A. It does not display ABC. The display is blank. In principle, according to the above session nfs sharing configuration, my A Service produces ABC, and my B server can read ABC automatically. It should also show ABC !! (Session NFS sharing test. Is there a problem with my PHP script ??)
Help me...Where is the error? The people of the world help me !!!
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