nginx配置apache服务器均衡负载出现400报错
个人博客地址:https://www.de009.top/nginx-configures-apache-server-balanced-load-with-400-reported-error.html
配置文件如下配置双机均衡负载。
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
access_log /var/log/nginx/access.log ;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
upstream load_balance_server {
server 192.168.1.1:8080 weight=1;
server 192.168.1.2 weight=2;
}
server {
listen 80;
server_name www.test.com;
#root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
root /var/www/html;
index index.html;
proxy_pass http://load_balance_server;
proxy_connect_timeout 90s;
proxy_buffers 4 32k;
proxy_temp_file_write_size 64k;
}
large_client_header_buffers 4 10k;
client_body_buffer_size 128k;
client_header_buffer_size 64;
}
}
配置完成后浏览器出现404错误
经过排查后发现是在配置中创建的服务器池名中有“_”下划线
upstream load_balance_server {
server 192.168.1.1:8080 weight=1;
server 192.168.1.2 weight=2;
}
#将load_balance_server改为loadbalanceserver即可使用,同时修改server配置块中的
proxy_pass http://load_balance_server;配置语句。
删除下划线后,服务器可正常访问。