Slime: Haproxy with Nginx, Zabbix integration

Source: Internet
Author: User
Tags nginx server haproxy

This article is sponsored by Ilanniweb, starting in Slime Line the world

To get more articles, you can follow my ilanniweb.

Yesterday introduced Haproxy's mobile phone matching rules, today to introduce the next Haproxy and Nginx, Zabbix integration. Next I will describe in detail the integration of Haproxy and Nginx directory browsing, and integration with Zabbix I will post the Haproxy configuration.

first, business needs

Due to business requirements, it is now time to expose some of the directories on the server to other systems to invoke the exposed files, but now require a 80 port HTTP service.

Analysis:

To achieve the above requirements, we will first provide the function of directory browsing, which we can use Apache or Nginx directory browsing function. Here, we are using Nginx Directory browsing function (that is, Nginx directory indexing function).

Then let Haproxy reverse proxy to nginx, you can achieve business needs.

Second, nginx configuration

Nginx installation is not listed here, we will look directly at the Nginx configuration file. As follows:

User Nginx;

Worker_processes 1;

Error_log/var/log/nginx/error.log warn;

Pid/var/run/nginx.pid;

Events {

Worker_connections 1024;

}

HTTP {

Include/etc/nginx/mime.types;

Default_type Application/octet-stream;

Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '

' $status $body _bytes_sent ' $http _referer '

' "$http _user_agent" "$http _x_forwarded_for";

Access_log/var/log/nginx/access.log main;

Sendfile on;

Keepalive_timeout 65;

gzip on;

server {

Listen 8088;

server_name 127.0.0.1;

CharSet Utf-8;

Access_log/var/log/nginx/log/host.access.log main;

location/testnginx/{

root/data/;

AutoIndex on;

}

}

}

Nginx Now we define the listener 8088 this port, and the opening is/data under the Testnginx this directory.

Note: This external directory name must be remembered, this name we will use in the haproxy matching rule.

After the Nginx configuration is complete, we choose to view the next Directory browsing function. As follows:

http://http.ilanni.com:8088/testnginx/

Through, we can clearly see Nginx directory browsing has been completely free of problems.

Three, haproxy configuration

After the Nginx configuration is complete, we will now configure the Haproxy. The configuration of the haproxy is simple.

You only need to match the name of the directory in the URL requested by the client. The specific configuration file is as follows:

Global

Log 127.0.0.1 Local0

Log 127.0.0.1 Local1 Notice

Maxconn 4096

UID 188

GID 188

Daemon

Tune.ssl.default-dh-param 2048

Defaults

Log Global

Mode http

Option Httplog

Option Dontlognull

Option Http-server-close

Option Forwardfor except 127.0.0.1

Option Redispatch

Retries 3

Option Redispatch

Maxconn 2000

Timeout Http-request 10s

Timeout Queue 1m

Timeout Connect 10s

Timeout Client 1m

Timeout Server 1m

Timeout Http-keep-alive 10s

Timeout Check 10s

Maxconn 3000

Listen Admin_stats

Bind 0.0.0.0:1080

Mode http

Option Httplog

Maxconn 10

Stats Refresh 30s

Stats Uri/stats

Stats Auth Admin:admin

Stats Hide-version

Frontend WEBLB

Bind *:80

ACL Is_nginx Url_beg/testnginx

ACL is_http Hdr_beg (host) http.ilanni.com

Use_backend Nginxserver if Is_nginx is_http

Use_backend Httpserver If Is_http

Backend Httpserver

Balance Source

Server Web1 127.0.0.1:8080 maxconn 1024x768 weight 3 check Inter rise 2 Fall 3

Backend Nginxserver

Balance Source

Server Web1 127.0.0.1:8088 maxconn 1024x768 weight 3 check Inter rise 2 Fall 3

In the Haproxy configuration file, we define a Is_nginx rule that matches the URL that starts with the Testnginx directory, and then forwards the rule to the Nginxserver server group on the back end. and the Nginxserver server group is the Nginx server.

This completes the Nginx integration with Haproxy.

Note: It is important to note that in this case, Haproxy matches the directory, the backend server group must exist the directory, otherwise it will be reported 404 error. This is what I know after I've stepped on a lot of holes.

Iv. Testing Integration Functions

After the Nginx integration with Haproxy configuration is complete, we choose to access the http://http.ilanni.com/testnginx/test its functionality as follows:

Through, we can clearly see that haproxy has been perfectly integrated with Nginx directory browsing functionality.

Five, haproxy and Zabbix integration

In the previous chapters we explained the functions of haproxy and Nginx integration, and in this chapter we introduce the functions of haproxy and Zabbix integration.

Zabbix Here we are using the Yum method to install, after the installation is complete, Apache listens to the 8099 port. The form of access is as follows:

http://zabbix.ilanni.com:8099/zabbix/

It is now required to use the 80 port directly to access the Zabbix,haproxy specific configuration as follows:

Global

Log 127.0.0.1 Local0

Log 127.0.0.1 Local1 Notice

Maxconn 4096

UID 188

GID 188

Daemon

Defaults

Log Global

Mode http

Option Httplog

Option Dontlognull

Option Http-server-close

Option Forwardfor except 127.0.0.1

Option Redispatch

Retries 3

Option Redispatch

Maxconn 2000

Timeout Http-request 10s

Timeout Queue 1m

Timeout Connect 10s

Timeout Client 1m

Timeout Server 1m

Timeout Http-keep-alive 10s

Timeout Check 10s

Maxconn 3000

Listen Admin_stats

Bind 0.0.0.0:1080

Mode http

Option Httplog

Maxconn 10

Stats Refresh 30s

Stats Uri/stats

Stats Auth Admin:admin

Stats Hide-version

Frontend WEBLB

Bind *:80

ACL Is_lianzhou Hdr_beg (host) zabbix.ilanni.com

ACL Is_zabbix Url_beg/zabbix

Use_backend Zabbix If Is_zabbix

Backend Zabbix

Balance Source

Server Web1 192.168.1.22:8099 maxconn 1024x768 weight 1 Check Inter rise 2 Fall 3

Haproxy configuration is simple, you only need to define a Is_zabbix url matching rule, and then distribute it to the back-end server group.

It is also important to note that the matching directory is present in the backend server.

After the configuration is complete, access is as follows:

http://zabbix.ilanni.com/zabbix/

Through, we can clearly see that haproxy and Zabbix have been perfectly integrated.

Slime: Haproxy with Nginx, Zabbix integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.