📜 ⬆️ ⬇️

NginX load balancing on Apache servers

Hello dear habro population.

I want to immediately warn you that I do not have much with grammar, since Russian is not native and I write and speak this language relatively recently, therefore I apologize in advance.

In the course of the work, two years ago we started a project that is based on HTML + PHP + MSSQL and of course the WEB-part of all this works on the famous Apache WEB-server. But over time, the load began to increase and it was time to distribute the load among several WEB-servers. After long discussions and disputes, we came to the following decision. Please switch your attention to the following scheme:

image
')
What is necessary to implement our scheme into reality:

1) NginX - proxy server for balancing traffic
2) Two Apache servers

In this article we will look at installing NginX-based traffic balancing server.
For this case we will choose the operating system CentOS 6.4

Our server has two network cards, one of which has access to the Internet, to configure it, go to our interface.

cd / etc / sysconfig / network-scripts

vi ifcfg-eth0

DEVICE = eth0
HWADDR = 00: 0C: 33: 6a: 90: F8
TYPE = Ethernet
UUID = de83281a-sa20-4791-b588-5621718adf4d
ONBOOT = yes
NM_CONTROLLED = yes
BOOTPROTO = static
IPADDR = 217.11.175.73
NETMASK = 255.255.255.224
GATEWAY = 217.11.175.33
DNS1 = 217.11.190.2


Now we have the Internet, then we set up a local network

cd / etc / sysconfig / network-scripts

vi ifcfg-eth0

DEVICE = eth1
HWADDR = 00: 0V: 35: 6a: 90: F3
TYPE = Ethernet
UUID = de83281a-sa10-4791-b577-5621718adf4d
ONBOOT = yes
NM_CONTROLLED = yes
BOOTPROTO = static
IPADDR = 192.168.1.3
NETMASK = 255.255.255.0


Now we will start the installation and the line of our proxy server for balancing our traffic

--- Update packages in CentOS
yum update -y


# wget nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
# rpm -ivh nginx-release-rhel-6-0.el6.ngx.noarch.rpm


- Getting started installing Nginx
yum install nginx -y


After installation in our directory
/ etc / nginx

NginX configuration files appear, then make backup of the existing file
cp nginx.conf /etc/nginx/nginx.conf.backup

after which we start changing the config file
rm nginx.conf


vi nginx.conf


Now we add our new config

# user and group from which the process starts
user nginx;

# 3 workflows
worker_processes 3;

# Error log
error_log /var/log/nginx/error.log debug;

events {
# maximum working connections
worker_connections 1024;
}

http {

# We connect the mime table
include mime.types;
# default mime type
default_type application / octet-stream;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;

# The module allows you to describe groups of servers that can be used.
# in the proxy_pass and fastcgi_pass directives.
upstream web {
# This parameter hashes the session by the first 4 acts of IP addresses, which is very helpful if someone uses asynchronous requests
ip_hash;
# Directive specifies server name and parameters. Please note we will
# use the name "pv" in the directive proxy_pass
server 192.168.28.8 weight = 2; # max_fails = 60 fail_timeout = 2s;
server 192.168.28.9 weight = 2; # max_fails = 60 fail_timeout = 2s;

}
server {
# Play port 80
listen 80;
location / {

# The proxy_pass directive mentioned earlier
proxy_pass web;
# Connect proxy settings
include /etc/nginx/proxy.conf;

}
}
}



In our config we have connected the proxy.conf file in which we specify the proxying parameters

proxy_redirect off;
proxy_set_header Host $ host;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
proxy_cache_bypass http;


Thanks for attention.

Source: https://habr.com/ru/post/213739/


All Articles