haproxy与nginx集成实例 By HKL, Wed
时间:2022-07-22
本文章向大家介绍haproxy与nginx集成实例
By HKL,
Wed,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
一、nginx的配置文件(主要部分)如下:
server1.conf
server {
listen 8189;
server_name 127.0.0.1;
root /opt/nginx/html/php;
index index.html index.htm index.php;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server2.conf
server {
listen 8189;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
root /opt/nginx/html/php;
index index.html index.htm index.php;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@test conf.d]# cat wp.conf
server {
listen 8188;
server_name 127.0.0.1;
root /opt/nginx/html;
index index.html index.htm index.php;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#include global/restrictions.conf;
#include global/wordpress.conf;
}
主要是将原来bind的server_name 0.0.0.0、端口都换成本地地址和端口,以腾出给haproxy使用。
二、haproxy配置文件(主要部分)如下: 只需要根据客户端请求的url中匹配目录的名称即可。具体配置文件如下:
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:10801
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 hdr_beg(host) test.ppuu.org
acl is_http hdr_beg(host) 42.123.77.14
use_backend nginxserver if is_nginx
use_backend httpserver if is_http
backend httpserver
balance source
server web1 127.0.0.1:8188 maxconn 1024 weight 3 check inter 2000 rise 2 fall 3
backend nginxserver
balance source
server web1 127.0.0.1:8189 maxconn 1024 weight 3 check inter 2000 rise 2 fall 3
三、效果 通过访问http://42.123.77.14 以及http://test.ppuu.org 可得出相应的效果。
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android WebView通过动态的修改js去拦截post请求参数实例
- Android使用Kotlin实现多节点进度条
- Android中webView加载H5绑定cookie实例
- 解决Android webview设置cookie和cookie丢失的问题
- Android实现清除单个域名的cookie
- Android实现触发html页面的Button控件点击事件方式
- webview添加参数与修改请求头的user-agent实例
- android webview获取html代码和根据id获取value实例
- pip 安装MySQL-python:EnvironmentError: mysql_config not found
- 关于WebView 重定向行为导致的多次加载的问题
- 解决webview内的iframe中的事件不可用的问题
- Android WebView拦截iframe标签内部跳转教程
- Android实现WebView点击拦截跳转原生
- Android实现带节点的进度条
- Android WebView userAgent 设置为桌面UA实例