Load balancing practice of nginx as a php site

WBOY
Release: 2016-08-08 09:28:17
Original
1039 people have browsed it

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.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!