Rotten mud: haproxy is integrated with nginx and zabbix, and haproxynginx

Source: Internet
Author: User

Rotten mud: haproxy is integrated with nginx and zabbix, and haproxynginx

This article is sponsored by ilanniweb and first published onThe world

For more articles, follow my ilanniweb.

Yesterday we introduced the mobile phone matching rules of haproxy. Today we will introduce the integration of haproxy with nginx and zabbix. Next, I will introduce in detail the integration of haproxy and nginx directory browsing function, and integrate with zabbix, I will post the haproxy configuration.

I. Business Requirements

Due to business requirements, some directories on the server should be exposed to other systems to call exposed files. However, port 80 http service is required for external use.

Analysis:

To meet the above requirements, we first need to provide the directory browsing function. We can use the directory browsing function of apache or nginx. Here, we use the nginx directory browsing function (that is, the nginx directory indexing function ).

Then let haproxy reverse proxy to nginx to achieve business needs.

Ii. nginx Configuration

The installation of nginx is not listed here. Let's look 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 is now defined to listen to port 8088, And the directory testnginx under/data is open to the outside world.

Note: This external directory name must be remembered. This name will be used in haproxy matching rules.

After nginx is configured, select to view the directory browsing function. As follows:

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

We can see that nginx directory browsing is completely normal.

3. haproxy Configuration

After nginx is configured, configure haproxy. The configuration of haproxy is simple.

You only need to match the directory name 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

Ults

Log global

Mode http

Option httplog

Option dontlognull

Option http-server-close

Option forwardfor partition t 127.0.0.1

Option redispatch

Retries 3

Option redispatch

Maxconn 2000

Timeout http-request 10 s

Timeout queue 1 m

Timeout connect 10 s

Timeout client 1 m

Timeout server 1 m

Timeout http-keep-alive 10 s

Timeout check 10 s

Maxconn 3000

Listen admin_stats

Bind 0.0.0.0: 1080

Mode http

Option httplog

Maxconn 10

Stats refresh 30 s

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 1024 weight 3 check inter 2000 rise 2 fall 3

Backend nginxserver

Balance source

Server web1 127.0.0.1: 8088 maxconn 1024 weight 3 check inter 2000 rise 2 fall 3

In the haproxy configuration file, we define an is_nginx rule that matches the url starting with the testnginx directory and then forwards the rule to the backend nginxserver server group, the nginxserver server group is the nginx server.

In this way, nginx and haproxy are integrated.

Note: Please note that the directory must exist in the backend server group when haproxy matches the directory. Otherwise, error 1.1 will be reported. This is only known after I step on many pitfalls.

Iv. Test the Integration Function

After nginx and haproxy are integrated and configured, we choose to access http://http.ilanni.com/testnginx/to test their functions, as shown below:

We can see that haproxy has been perfectly integrated with the nginx directory browsing function.

5. Integration of haproxy and zabbix

In the previous sections, we have explained the Integration Functions of haproxy and nginx. In this section, we will introduce the Integration Functions of haproxy and zabbix.

Zabbix is installed using the yum method here. After installation, apache listens to port 8099. The access method is as follows:

Http://zabbix.ilanni.com: 8099/zabbix/

Now we need to directly use port 80 to access zabbix. The specific configuration of haproxy is as follows:

Global

Log 127.0.0.1 local0

Log 127.0.0.1 local1 notice

Maxconn 4096

Uid 188

Gid 188

Daemon

Ults

Log global

Mode http

Option httplog

Option dontlognull

Option http-server-close

Option forwardfor partition t 127.0.0.1

Option redispatch

Retries 3

Option redispatch

Maxconn 2000

Timeout http-request 10 s

Timeout queue 1 m

Timeout connect 10 s

Timeout client 1 m

Timeout server 1 m

Timeout http-keep-alive 10 s

Timeout check 10 s

Maxconn 3000

Listen admin_stats

Bind 0.0.0.0: 1080

Mode http

Option httplog

Maxconn 10

Stats refresh 30 s

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 1024 weight 1 check inter 2000 rise 2 fall 3

Haproxy is easy to configure. You only need to define an is_zabbix url matching rule and distribute it to the backend server group.

Note that the matched directory exists on the backend server.

After the configuration is complete, access the following:

Http://zabbix.ilanni.com/zabbix/

We can see that haproxy and zabbix have been perfectly integrated.

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.