Load balancing practice of nginx as a php site
Aug 08, 2016 am 09:28 AMA lamp application I am responsible for needs to improve high availability, so I chose nginx as the load balancing tool.
nginx needs to modify the nginx.conf configuration:
<code>upstream qss { <span>82</span> server <span>10.46</span><span>.194</span><span>.17</span>:<span>8088</span> weight<span>=</span><span>5</span>; <span>83</span> server <span>10.46</span><span>.192</span><span>.41</span>:<span>8080</span> weight<span>=</span><span>5</span>; <span>84</span> } <span>85</span><span>86</span> server { <span>87</span> listen <span>8079</span>; <span>88</span> server_name cq01<span>-tdw</span><span>-bfe28</span><span>.</span>cq01<span>.</span>baidu<span>.</span>com; <span>89</span> underscores_in_headers <span>on</span>; <span>90</span> ignore_invalid_headers off; <span>91</span><span>92</span> location <span>/</span> { <span>93</span> proxy_set_header Host <span>$host</span>; <span>94</span> proxy_set_header X<span>-Real</span><span>-IP</span><span>$remote_addr</span>; <span>95</span> proxy_set_header X<span>-Forwarded</span><span>-For</span><span>$proxy_add_x_forwarded_for</span>; <span>96</span> proxy_pass http:<span>//qss;</span><span>97</span> }</code>
Among them, underscores_in_headers on means that header fields containing underscores are considered legal. If there are underscore fields in the header, this must be set, otherwise it will be prompted in nginx's error_log mistake.
In addition, the site has a session, so the session should be shared in each php module. You can modify the configuration of the php.ini file. It was previously saved in a tmp file. Now, it can be saved in memcached:
<code><span>732</span> extension_dir = <span>"/home/qec/vlamp/build/php/output/lib/php/extensions/no-debug-non-zts-20100525/"</span><span>733</span> extension = memcache<span>.so</span><span>1365</span> [Session] <span>1366</span><span>; Handler used to store/retrieve data.</span><span>1367</span><span>; http://php.net/session.save-handler</span><span>1368</span><span>; session.save_handler = files</span><span>1369</span> session<span>.save</span>_handler = memcache <span>1370</span> memcache<span>.hash</span>_strategy = <span>"consistent"</span><span>1371</span> session<span>.save</span>_path = <span>"tcp://10.216.122.21:11211"</span></code>
Then, that's it.
The above introduces the load balancing practice of nginx as a PHP site, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Overview of NginxProxyManager configuration analysis and optimization: NginxProxyManager is a reverse proxy management tool based on Nginx, which can help us easily configure and manage reverse proxy servers. In the process of using NginxProxyManager, we can improve the performance and security of the server by parsing and optimizing its configuration. Configuration analysis: Configuration file location and structure: NginxProxyManag

When proxyprotocol is used in nginx, we know that nginx is a web server and proxy server. It generally works behind proxyserver or load balancing software (Haproxy, Amazon Elastic LoadBalancer (ELB)). The client first requests proxyserver or LSB load balancing software, and then to nginx Perform real web access. Because it has gone through multiple layers of software, some client information such as IP address, port number, etc. may be hidden, which is detrimental to our problem analysis and data statistics. Because for nginx, We want to be able to get real clients

How to use NginxProxyManager to achieve load balancing of multiple servers. NginxProxyManager is a proxy server management tool developed based on Nginx. It provides a simple and easy-to-use Web interface that can easily configure and manage Nginx proxy servers. In practical applications, we often need to distribute requests to multiple servers to achieve load balancing and improve system performance and availability. This article will introduce how to use NginxProx

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Problem: Today, we encountered a setting timeout problem in our project, and changes to SpringBoot2’s application.properties never took effect. Solution: The server.* properties are used to control the embedded container used by SpringBoot. SpringBoot will create an instance of the servlet container using one of the ServletWebServerFactory instances. These classes use server.* properties to configure the controlled servlet container (tomcat, jetty, etc.). When the application is deployed as a war file to a Tomcat instance, the server.* properties do not apply. They do not apply,

Log analysis and monitoring of NginxProxyManager requires specific code examples. Introduction: NginxProxyManager is a proxy server management tool based on Nginx. It provides a simple and effective method to manage and monitor proxy servers. In actual operation, we often need to analyze and monitor the logs of NginxProxyManager in order to discover potential problems or optimize performance in time. This article will introduce how to use some commonly used

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

The deployment strategy of containers and microservices under NginxProxyManager requires specific code examples. Summary: With the popularity of microservice architecture, containerization technology has become an important part of modern software development. In the microservice architecture, NginxProxyManager plays a very important role, used to manage and proxy the traffic of microservices. This article will introduce how to use NginxProxyManager to deploy and manage containerized microservices, and provide relevant code examples.
