Haproxy Lab Notes

Source: Internet
Author: User
Tags sendfile haproxy

Experimental planning:

Host Name IP Address Role
Node01 192.168.112.128 Web01
Node02 192.168.112.129 Web02
Node03 192.168.112.130 Haproxy

Operating System Information:

[Email protected] ~]# cat/etc/redhat-release

CentOS Release 6.6 (Final)

[Email protected] ~]# uname-a

Linux node03 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 04:27:16 UTC x86_64 x86_64 x86_64 gnu/linux

[Email protected] ~]#

Install Haproxy:

[Email protected] ~]# yum-y install haproxy nginx php

Install nginx PHP:

[[email protected] ~]# yum-y install Nginx

[[email protected] ~]# yum-y install Nginx

Node01 and NODE02 on nginx configuration files:

User Nginx;

Worker_processes 4;


#error_log Logs/error.log;

#error_log Logs/error.log Notice;

#error_log Logs/error.log Info;


#pid Logs/nginx.pid;



Events {

Worker_connections 1024;

}



HTTP {

Include Mime.types;

Default_type Application/octet-stream;


server {

Listen 80;

server_name localhost;


#charset Koi8-r;


#access_log Logs/host.access.log Main;


Location/{

root HTML;

Index index.html index.htm;

}

}


Node03 on Haproxy and nginx configuration files

Haproxy

Global

Log 127.0.0.1 Local2


Chroot/var/lib/haproxy

Pidfile/var/run/haproxy.pid

Maxconn 4000

User Haproxy

Group Haproxy

Daemon


# Turn on stats UNIX socket

Stats Socket/var/lib/haproxy/stats


Defaults

Mode http

Log Global

Option Httplog

Option Dontlognull

Option Http-server-close

Option Forwardfor except 127.0.0.0/8

Option Redispatch

Retries 3

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 S-monitor *:90

Mode http

Stats enable

Stats Refresh 5s

Stats Realm New0ldname

Stats URI/

Stats Auth user:123456

Frontend main *:80

ACL url_static path_beg-i/static/images/javascript/stylesheets

ACL url_static path_end-i. jpg. gif. png. css. js


Use_backend Static If Url_static

Default_backend app


Backend static

Balance Roundrobin

Server static 127.0.0.1:8080 Check


Backend app

Balance Roundrobin

Server App1 192.168.112.128:80 Check

Server APP2 192.168.112.129:80 Check

Nginx configuration file:

User Nginx;

Worker_processes 4;


#error_log Logs/error.log;

#error_log Logs/error.log Notice;

#error_log Logs/error.log Info;


#pid Logs/nginx.pid;



Events {

Worker_connections 1024;

}



HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Sendfile on;

User Nginx;

Worker_processes 4;


#error_log Logs/error.log;

#error_log Logs/error.log Notice;

#error_log Logs/error.log Info;


#pid Logs/nginx.pid;



Events {

Worker_connections 1024;

}



HTTP {

Include 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 Logs/access.log Main;


Sendfile on;

#tcp_nopush on;


#keepalive_timeout 0;

Keepalive_timeout 65;


#gzip on;


server {

Listen 8080;

server_name localhost;


#charset Koi8-r;


#access_log Logs/host.access.log Main;

Root/data/website/app;

Location/{

#root html;

Index index.php index.html index.htm;

}


#error_page 404/404.html;


# REDIRECT Server error pages to the static page/50x.html

#

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}


# Proxy The PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# Proxy_pass http://127.0.0.1;

#}


# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

Location ~ \.php$ {

root HTML;

Fastcgi_pass 127.0.0.1:9000;

Fastcgi_index index.php;

Fastcgi_param script_filename $document _root$fastcgi_script_name;

Include Fastcgi_params;

}


This article from "Flat Light is true" blog, please be sure to keep this source http://ucode.blog.51cto.com/10837891/1880704

Haproxy Lab Notes

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.