nginx反向代理+负载均衡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx反向代理+负载均衡相关的知识,希望对你有一定的参考价值。
nginx反向代理多个工程,加入了负载均衡及动静分离的配置
#user nobody;
worker_processes 4;
error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
worker_connections 65535;
}
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"‘;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_send_timeout 60;
proxy_read_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
access_log logs/access.log main;
gzip on;
#负载均衡
upstream bsxm {
ip_hash;
server 192.168.1.193:8080;
}
#指定静态页面路径
server {
listen 80;
server_name 192.168.1.193;
root C:\webapps\bsxmgw\pages;
index index.html index.htm;
#反向代理配置
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#纯反向代理配置
#location /webapps/
#{
# proxy_pass http://192.168.1.193:8080;
#}
#负载均衡
location ~ \.(jsp|action)$
{
proxy_pass http://bsxm;
# client_max_body_size 1000m;
}
location ~ \.(gif|jpg|jpeg|png|bmp|swf|flv)$
{
expires 30d;#所有静态文件缓存30天
}
location ~ \.(js|css)?$
{
expires 1h;
}
}
#反向代理工程
location /b/ {
proxy_pass http://192.168.1.193:8080/b/;
root C:\webapps\b;
#proxy_redirect http://host:8080 http://$host:$server_port;
index index.html index.htm;
}
#反向代理工程
location /a/ {
proxy_pass http://192.168.1.193:8080/a/;
root C:\webapps\a;
#proxy_redirect http://host:8080 http://$host:$server_port;
index index.html index.htm;
}
#访问地址为http://localhost/a http://localhost/b
#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;
}
}
}
本文出自 “风之然” 博客,转载请与作者联系!
以上是关于nginx反向代理+负载均衡的主要内容,如果未能解决你的问题,请参考以下文章
nginx反向代理访问很慢,我做了负载均衡,现在几乎无法访问,有谁能帮我解决一下,万分感谢。