#y proxy_connect_timeout 2s; upstream tomcat_pool { server 10.10.1.144:8080; server 10.10.1.152:80; server 10.10.1.155:8080; } upstream report_pool { server 10.10.1.150:8080; #server 127.0.0.1:8081 down; } #y
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} proxy_buffer_size 16k; proxy_buffers 4 16k; location / { proxy_pass http://tomcat_pool/; proxy_set_header Host $host; 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; }
举例:
#user nobody; worker_processes 1; #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; upstream kettas{ server 127.0.0.1:8080; server 127.0.0.1:8090; ip_hash ; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; proxy_pass http://kettas; proxy_set_header Host $host; 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; } #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; } # 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 /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
注意:
nginx不支持session共享,可以用ip_hash方案解决(上例),昨天遇到一个问题是上传文件出错的问题。(于是用chrome跟踪发现了413异常。问了下度娘她说是nginx默认的上传文件大小受限制。)于是有了以下的配置:
在nginx.conf的http{}中增加 client_max_body_size 20m;
相关推荐
lvs+nginx负载均衡,lvs+nginx负载均衡,lvs+nginx负载均衡,lvs+nginx负载均衡
主要介绍了nginx负载均衡配置,宕机自动切换方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
nginx 负载均衡与缓存服务器标准配置文件
基于nginx负载均衡的集群聊天系统,其中技术点有网络方面、数据库方面、线程安全方面;功能点有添加好友、单人聊天、群组聊天等 基于nginx负载均衡的集群聊天系统,其中技术点有网络方面、数据库方面、线程安全方面...
nginx 完成服务器之间集群的搭建 能够解决服务器调用负载均衡
nginx负载均衡配置文件实例:基本配置说明文档和一个配置好的nginx.conf文件实例
企业级keepalived高可用实战与Nginx负载均衡视频教程.zip
Nginx负载均衡搭建及配置技术,尽可能详细介绍了相关配置用法及静态资源配置相关,提高服务器运行及运维方面的知识
Tomcat在高并发环境下处理动态请求时性能很低,而在处理静态页面更加脆弱。是通过Nginx来处理静态页面要比通过Tomcat处理在性能方面好很多。本例为nginx负载均衡配置方法
在一台服务器的操作系统上,安装一个附加软件来实现负载均衡,如Nginx负载均衡(我们管理系统平台使用的也是这款均衡器)。它的优点是基于特定环境、配置简单、使用灵活、成本低廉,可以满足大部分
nginx负载均衡ssl证书认证强制跳转https+keeplived+apache
linux下安装Nginx并做到负载均衡,配置详细在文档有介绍!
该文档以Nginx为基础,详细梳理了负载均衡的原理,以及优化方式,和实现步骤,无论新手还是大虾都可以从中得到深入体会。
nginx 负载均衡 反向代理 nginx 负载均衡 反向代理 nginx 负载均衡 反向代理
阿里云服务器搭建nginx负载均衡
linux下的nginx搭建的负载均衡,nginx.conf文件修改成自己对应的地址即可直接使用,将配置复制进windows版本的nginx下应该也可用,这个没有测试,有问题,请联系哦
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器... Nginx 支持简单的负载均衡和容错; 支持作为基本 HTTP 服务器的功能,例如日志、压缩、Byte ranges、Chunked responses、SSL、虚拟主机等等,应有尽有
Nginx的特点是: ... 2、Nginx对网络的依赖比较小; 3、Nginx安装和配置比较简单,测试起来比较方便; 4、也可以承担高的负载压力且稳定,一般能支撑超过1万... 另外默认的只有Round-robin和IP-hash两种负载均衡算法。
nginx经常用到的负载均衡的5种策略,注意细节,部分属性不能一起使用。
基于lua的nginx自定义负载均衡基于lua的nginx自定义负载均衡