


Nginx and PHP installation and configuration: 5 strategies for nginx load balancing
This article shares with you the five strategies for installing and configuring Nginx and PHP seven nginx load balancing. It has certain reference value. Friends in need can refer to it
nginxYou can perform load balancing based on the client IP. By setting ip_hash in upstream, you can select the same client for the same class C address segment. A backend server, unless that backend server is down, it will be replaced.
nginx's upstream Currently supports 5 ways of allocation
1, polling (default)
Every Requests are assigned to different back-end servers one by one in chronological order. If the back-end server goes down, it can be automatically eliminated.
upstream backserver {
server 192.168.0.14;
server 192.168.0.15;
}
##2, Specify the weight
to specify the polling probability. The weight is proportional to the access ratio and is used when the back-end server performance is uneven.
upstream backserver {
server 192.168.0.14 weight=10;
server 192.168.0.15 weight=10; ##}
3, IPBind ip_hashEach request is allocated according to the hash result of accessing ip
, so that each visitor has a fixed access to one post The end server can solve the session problem. upstream backserver {
ip_hash;
server 192.168. 0.14:88;
#server 192.168.0.15:80;
}
4
, fair (third party) Press the response of the backend server Time is allocated to requests, and those with short response times are allocated first.
upstream backserver {
server server1;
server server2;
fair;
##}
##5
, url_hash
(third party) Distributed according to the hash result of accessing url Request so that each URL is directed to the same backend server. It is more effective when the backend server is cached.
upstream backserver {
server squid1:3128;
server squid2:3128;
hash $request_uri;
##hash_method crc32;
}
Add
to the server
that needs to use load balancing proxy_pass http://backserver/;
upstream backserver{ ##ip_hash;
server 127.0.0.1:9090 down; (down
means that the previous server will not participate in the load temporarily) server 127.0.0.1:8080 weight=2; (weight defaults to 1. The larger the weight, the greater the weight of the load)
server 127.0.0.1:6060;
##server 127.0.0.1:7070 backup; (All other non-backup machines When down or busy, request the backup machine)
}
max_fails : Allow The default number of request failures is 1.When the maximum number of requests is exceeded, the error defined by the proxy_next_upstream module is returned
fail_timeout:max_failsThe pause time after failures
Reference article:
##http://www.cnblogs.com/andashu/p/6377323.html
http: //blog.csdn.net/xiajun07061225/article/details/9318871
Related recommendations:
Nginx and PHP Installation and Configuration Sixth Nginx Reverse Proxy and Load Balancing Deployment Guide Nginx and php installation and configuration 5. LINUX Use PHPIZE to install PHP GD extensionNginx and php installation and configuration 4. nginx and php Start or restartThe above is the detailed content of Nginx and PHP installation and configuration: 5 strategies for nginx load balancing. For more information, please follow other related articles on the PHP Chinese website!

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

Setting the httponly flag is crucial for session cookies because it can effectively prevent XSS attacks and protect user session information. Specifically, 1) the httponly flag prevents JavaScript from accessing cookies, 2) the flag can be set through setcookies and make_response in PHP and Flask, 3) Although it cannot be prevented from all attacks, it should be part of the overall security policy.

PHPsessionssolvetheproblemofmaintainingstateacrossmultipleHTTPrequestsbystoringdataontheserverandassociatingitwithauniquesessionID.1)Theystoredataserver-side,typicallyinfilesordatabases,anduseasessionIDstoredinacookietoretrievedata.2)Sessionsenhances

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor
