时间:2020-03-05来源:电脑系统城作者:电脑系统城
以下是用于配置nginx负载平衡的简单示例文件。 主要功能是:
用户访问http://www.linuxidc.com并将其负载均衡到四台服务器:192.168.5.2:80、92.168.1.3:80、192.168.5.4:80、192.168.1.5:80
用户访问http://m.linuxidc.com并将其负载均衡到192.168.5.7服务器的端口8080、8081和8082。
user www www;
worker_processes 10;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include conf/mime.types;
default_type application/octet-stream;
keepalive_timeout 120;
tcp_nodelay on;
upstream www.linuxidc.com {
server 192.168.5.2:80;
server 192.168.5.3:80;
server 192.168.5.4:80;
server 192.168.5.5:80;
}
upstream m.linuxidc.com {
server 192.168.5.7:8080;
server 192.168.5.7:8081;
server 192.168.5.7:8082;
}
server
{
listen 80;
server_name www.linuxidc.com;
location / {
proxy_pass http://www.linuxidc.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
log_format www_linuxidc_com ‘$remote_addr – $remote_user [$time_local] $request ‘
‘”$status” $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;
access_log /data1/logs/www.log www_linuxidc_com;
}
server
{
listen 80;
server_name m.linuxidc.com;
location / {
proxy_pass http://m.linuxidc.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
log_format linuxidc_linuxidc_com ‘$remote_addr – $remote_user [$time_local] $request ‘
‘”$status” $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;
access_log /data1/logs/linuxidc.log blog_linuxidc_com;
}
}
这里使用两个主要模块:
1. HTTP负载平衡模块(HTTP上游),解释了一些字段:
2. HTTP代理模块(HTTP Proxy)
该模块可以将请求转发到其他服务器。
2024-07-07
myeclipse怎么导入tomcat教程2024-07-07
myeclipse如何启动tomcat2024-07-07
myeclipse如何绑定tomcat上线了一个小的预约程序,配置通过Nginx进行访问入口,默认的日志是没有请求时间的,因此需要配置一下,将每一次的请求的访问响应时间记录出来,备查与优化使用....
2023-03-17