`

Nginx简单配置(二)负载均衡

 
阅读更多

 

#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 aaa{

      server localhost:8080 weight=10 max_fails=2 fail_timeout=30s; #weight权重,值越大,在负载均衡时分配的请求越多  

  #tomcat配置 <Context docBase="boss" path="/" reloadable="true" source="org.eclipse.jst.jee.server:boss"/></Host> path改为 / 原为 "/boss"

}   #1.down 表示单前的server暂时不参与负载 

#2.weight 默认为1.weight越大,负载的权重就越大。 

#3.max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误 

#4.fail_timeout:max_fails次失败后,暂停的时间。 

#5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。 

 

    server {

        listen       80;

        server_name  localhost;

index index.jsp index.htm index.php;

#root D:\Nginx;  ##项目目录 D:\Nginx\boss\WEB-INF

 

        #charset koi8-r;

 

        #access_log  logs/host.access.log  main;

 

#location / {

        #   root   html;

        #    index  index.html index.htm;   ##进入nginx 的html文件夹下的 index页, 在index 页进行重定向

        #}

 

location / {

            proxy_pass http://aaa;  ##引用upstream 

        }

  

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|txt)$ {  

root D:\Nginx\boss;

expires 24h; #设置过期时间  

  

 

location ~ .*\.(js|css)?$

                {

root D:\Nginx\boss;

                                expires      12h;

                }

 

        #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;

    #    }

    #}

 

}

 

分享到:
评论

相关推荐

    FreeBSD下用nginx配置简单web负载均衡

    FreeBSD 8.1下用nginx配置简单web负载均衡

    nginx+tomcat负载均衡简单配置

    nginx+tomcat负载均衡简单配置

    负载均衡器技术Nginx和F5的优缺点对比

     我们使用的是软负载均衡器Nginx,而农行用的是F5硬负载均衡器,这里简单介绍下这两种技术:  a、软件负载均衡解决方案  在一台服务器的操作系统上,安装一个附加软件来实现负载均衡,如Nginx负载均衡(我们...

    nginx+tomcat 负载均衡简易配置与动静分离

    小型网站上进行的nginx+tomcat负载均衡与动静分离

    Nginx与Tomcat配置实现负载均衡.zip

    配置简单易懂,只需对nginx和tomcat集群稍作配置即可实现

    nginx负载均衡 nginx+tomcat tomcat实现负责均衡

    Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器... Nginx 支持简单的负载均衡和容错; 支持作为基本 HTTP 服务器的功能,例如日志、压缩、Byte ranges、Chunked responses、SSL、虚拟主机等等,应有尽有

    Nginx+Tomcat负载均衡

    3、Nginx+Tomcat负载均衡配置 首先创建两个文件,这两个文件 我来提供,将这两个文件拷入Nginx的conf文件夹下 1.proxy.conf 文件内容 #负责代理转发 proxy_redirect off; proxy_set_header Host $host; proxy_set_...

    Nginx负载均衡与地址映射配置的完整配置

    这里已经完整的配置了nginx的地址映射和负载均衡,只需要将里面的服务改成本地的多个Tomcat的就行了。关注我 可以到2017-4-29写的博客看详情 博客名:简单认识Nginx---负载均衡

    Nginx的负载均衡入门-张宴

    Nginx的负载均衡入门-张宴 Nginx的负载均衡入门-张宴

    nginx+tomcat搭建负载均衡

    简单通过nginx+tomcat搭建负载均衡,rar包内提供nginx工具及搭建配置说明文档word

    Nginx负载均衡特点

    3、Nginx安装和配置比较简单,测试起来比较方便; 4、也可以承担高的负载压力且稳定,一般能支撑超过1万次的并发; 5、Nginx可以通过端口检测到服务器内部的故障, 比如根据服务器处理网页返回的状态码、超时...

    nginx负载均衡配置

    nginx负载均衡配置手册,最简单的配置实现两台服务器的负载。

    nginx、负载均衡

    使用nginx搭建web负载均衡,方便使用,简单,快捷。。

    Nginx配置负载均衡和缓存详解

    简单介绍Nginx,实现负载均衡的配置和使用缓存存储静态资源文件,并可以通过purge模块删除缓存

    CentOS基于nginx反向代理实现负载均衡的方法

    本文实例讲述了CentOS基于nginx反向代理实现负载均衡的方法。分享给大家供大家参考,具体如下: nginx做负载均衡的优点: 1、工作在网络的7层之上,可以针对http应用做一些分流的策略,比如针对域名、目录结构,它的...

    Linux 系统 nginx 服务器安装及负载均衡配置详解

    本文主要介绍在测试环境中通过 nginx 实现基本的 负载均衡 功能。 nginx 可以提供 HTTP 服务,包括处理静态文件,支持 SSL 和 TLS SNI、GZIP 网页压缩、虚拟主机、URL 重写等功能,可以搭配 FastCGI、uwsgi 等程序...

    Nginx+SpringBoot实现负载均衡的示例

    在介绍Nginx的负载均衡实现之前,先简单的说下负载均衡的分类,主要分为硬件负载均衡和软件负载均衡,硬件负载均衡是使用专门的软件和硬件相结合的设备,设备商会提供完整成熟的解决方案,比如F5,在数据的稳定性...

    nginx+tomcat在windows下做负载均衡

    目前可以和Tomcat做负载均衡的主流服务器是Apache,但是Nginx由于功能多、配置简单等优点逐渐成为很多负载均衡服务器的首选。Nginx的并发数可达到50000,所以理论上可以和Tomcat以1:100的比例来配置,这样便可以很好...

    nginx简单实现负载均衡

    负载均衡服务概念 作用: 1)实现并发访问压力分担 2)实现访问调度处理 根据用户终端不同进行调度访问 /根据服务器性能 实现方式: 软件方式实现 nginx lvs haproxy 硬件方式实现 F5 A10 负载均衡 名词解释: 负载...

    详解 Nginx 负载均衡和反向代理配置和优化

    Nginx 负载均衡和反向代理配置和优化 DNS 轮询方式: 介绍: DNS 轮询是指一个域名可以绑定到多个的 ip 服务器上, 用户在访问的时候 dns轮询访问这几个 ip 的服务器, 达到负载均衡的目的. 可以使用 linux 命令 dig ...

Global site tag (gtag.js) - Google Analytics