Home Backend Development PHP Tutorial Load balancing practice of nginx as a php site

Load balancing practice of nginx as a php site

Aug 08, 2016 am 09:28 AM
handler header proxy session

A 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>
Copy after login

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>
Copy after login

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.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1264
29
C# Tutorial
1237
24
Nginx Proxy Manager configuration analysis and optimization Nginx Proxy Manager configuration analysis and optimization Sep 26, 2023 am 09:24 AM

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

How to configure and use proxy protocol in nginx How to configure and use proxy protocol in nginx May 18, 2023 am 08:47 AM

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 set session timeout in SpringBoot Session How to set session timeout in SpringBoot Session May 15, 2023 pm 02:37 PM

The problem was found in the springboot project production session-out timeout. The problem is described below: In the test environment, the session-out was configured by changing the application.yaml. After setting different times to verify that the session-out configuration took effect, the expiration time was directly set to 8 hours for release. Arrived in production environment. However, I received feedback from customers at noon that the project expiration time was set to be short. If no operation is performed for half an hour, the session will expire and require repeated logins. Solve the problem of handling the development environment: the springboot project has built-in Tomcat, so the session-out configured in application.yaml in the project is effective. Production environment: Production environment release is

Deployment strategy of containers and microservices under Nginx Proxy Manager Deployment strategy of containers and microservices under Nginx Proxy Manager Sep 27, 2023 pm 01:06 PM

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.

How to solve session failure How to solve session failure Oct 18, 2023 pm 05:19 PM

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.

Solution to PHP Session cross-domain problem Solution to PHP Session cross-domain problem Oct 12, 2023 pm 03:00 PM

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

Nginx Proxy Manager Tutorial: Quick Start Guide Nginx Proxy Manager Tutorial: Quick Start Guide Sep 27, 2023 pm 05:39 PM

NginxProxyManager Tutorial: Quick Start Guide, Specific Code Examples Needed Introduction: With the development of network technology, proxy servers have become a part of our daily use of the Internet. NginxProxyManager is a proxy server management platform based on Nginx, which can help us quickly establish and manage proxy servers. This article will introduce you to the quick start guide of NginxProxyManager, as well as some specific code examples. one

How to use Nginx Proxy Manager to achieve load balancing of multiple servers How to use Nginx Proxy Manager to achieve load balancing of multiple servers Sep 27, 2023 pm 09:42 PM

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

See all articles