Nginx反向代理,负载均衡配置

主配置文件:nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user www;
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections  102400;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}

目录下 /etc/nginx/conf.d/one.conf

#
# The default server
#

upstream one_server{
    server 127.0.0.1:8090 weight=1;
    #server 127.0.0.1:8091 weight=1;
}

server {
    listen       80;
    server_name  one.server.com;

    #charset koi8-r;

    access_log  /data/logs/one.access.log  main;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {

        index  index.htm index.html;

        proxy_pass   http://one_server;    #在这里设置一个代理,和upstream的名字一样
        #以下是一些反向代理的配置可删除
        proxy_redirect             off;
        #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
        proxy_set_header           Host $host;
        proxy_set_header           X-Real-IP $remote_addr;
        proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size       10m; #允许客户端请求的最大单文件字节数
        client_body_buffer_size    128k; #缓冲区代理缓冲用户端请求的最大字节数
        proxy_connect_timeout      300; #nginx跟后端服务器连接超时时间(代理连接超时)
        proxy_send_timeout         300; #后端服务器数据回传时间(代理发送超时)
        proxy_read_timeout         300; #连接成功后,后端服务器响应时间(代理接收超时)
        proxy_buffer_size          4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
        proxy_buffers              4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
        proxy_busy_buffers_size    64k; #高负荷下缓冲大小(proxy_buffers*2)
        proxy_temp_file_write_size 64k;

    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/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
    #

    # deny access to .htaccess files, if Apache‘s document root
    # concurs with nginx‘s one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

可以增加多个 one.conf 文件配置多个系统的负载均衡,反向代理

单独的图片服务器:img111.conf

#
# The default server
#
server {
    listen       80;
    server_name  img111.server.com;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        root   /data/www/webapp/;
        index  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/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
    #

    # deny access to .htaccess files, if Apache‘s document root
    # concurs with nginx‘s one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
时间: 2024-08-03 04:27:02

Nginx反向代理,负载均衡配置的相关文章

Centos7.4 Nginx反向代理+负载均衡配置

Ningx是一款高性能的HTTP和反向代理服务器,配置起来也比较简单. 测试环境: 172.16.65.190 Nginx-反向代理 172.16.65.191 Ningx-Web 172.16.65.192 Nginx-Web 在三台Server安装Nginx: # yum install -y nginx 在172.16.65.190配置Nginx反向代理+负载均衡: # vim /etc/nginx/nginx.conf user nginx; worker_processes auto;

nginx反向代理负载均衡配置

LB: nginx.conf worker_processes  1; events {     worker_connections  1024; } http {     include       mime.types;     default_type  application/octet-stream;     sendfile        on;     keepalive_timeout  65;     upstream www_server_pools {     serve

25,Nginx反向代理负载均衡

1,什么是反向代理1,代理顾名思义就是代理某人去做某事,比如律师代理,中介代理.往往你不能直接自己做的事,都需要找代理 2,为什么要用反向代理1,在没有代理服务器之前,用户访问web服务器是如下图:2,在实际业务生成环境中,比如我们访问web服务器,在用户和服务器直接往往有一台或者多台代理服务器用来转发你的访问请求,代你去访问web服务器,然后将结果返回给用户.当你只有一台web服务器的时候,这种代理看起来其实意义不大,用户直接访问web服务器不是更快?但生产中不仅仅一台web,这个时候用代理来

nginx反向代理负载均衡简述

基于浏览器实现分离案例if ($http_user_agent ~ Firefox) {rewrite ^(.)$ /firefox/$1 break;}if ($http_user_agent ~ MSIE) {rewrite ^(.)$ /msie/$1 break;}if ($http_user_agent ~ Chrome) {rewrite ^(.*)$ /chrome/$1 break;} 防盗链案例:location ~* .(jpg|gif|jpeg|png)$ {valid_r

Centos 7配置nginx反向代理负载均衡集群

一,实验介绍 利用三台centos7虚拟机搭建简单的nginx反向代理负载集群, 三台虚拟机地址及功能介绍 192.168.2.76    nginx负载均衡器 192.168.2.82    web01服务器 192.168.2.78    web02服务器 二,安装nginx软件(以下操作三台虚拟机都要进行)1,安装依赖软件包命令集合 yum -y install openssl openssl-devel pcre pcre-devel gcc 2,安装nginx软件包命令集合 mkdir

如何使用Weave以及Docker搭建Nginx反向代理/负载均衡服务器

Hi, 今天我们将会学习如何使用 Weave 和 Docker 搭建 Nginx 的反向代理/负载均衡服务器.Weave 可以创建一个虚拟网络将 Docker 容器彼此连接在一起,支持跨主机部署及自动发现.它可以让我们更加专注于应用的开发,而不是基础架构.Weave 提供了一个如此棒的环境,仿佛它的所有容器都属于同个网络,不需要端口/映射/连接等的配置.容器中的应用提供的服务在 weave 网络中可以轻易地被外部世界访问,不论你的容器运行在哪里.在这个教程里我们将会使用 weave 快速并且简单

项目实战2.2—nginx 反向代理负载均衡、动静分离和缓存的实现

实验一:实现反向代理负载均衡且动静分离 1.环境准备: 机器名称 IP配置 服务角色 备注 nginx VIP:172.17.11.11 反向代理服务器 开启代理功能 设置监控,调度 rs01 RIP:172.17.22.22 后端服务器 stasic-srv 组 rs02 RIP:172.17.1.7 后端服务器 stasic-srv 组 rs01 RIP:172.17.77.77 后端服务器 defautl-srv 组 rs02 RIP:172.17.252.111 后端服务器 defaut

项目实战02:nginx 反向代理负载均衡、动静分离和缓存的实现

目录 实验一:实现反向代理负载均衡且动静分离 1.环境准备: 2.下载编译安装tengine 3.设置代理服务器的配置文件 4.启动tengine服务 5.开启后端的web服务 6.测试 实验二:nginx实现缓存功能 1.环境准备:同上实验,实验结构图如下: 2.设置代理服务器的配置文件 3.测试:访问 http://172.17.11.11/ 总项目流程图,详见http://www.cnblogs.com/along21/p/7435612.html 回到顶部 实验一:实现反向代理负载均衡且

nginx反向代理负载均衡

1.反向代理概述 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器. 环境准备: 主机名 IP地址 角色 系统 web-node1.com eth0:192.168.90.201 web-node1节点 CentOS7.2 web-node2.com eth0:192.168.90.202 web-node

Nginx 反向代理 负载均衡 虚拟主机配置

通过本章你将学会利用Nginx配置多台虚拟主机,清楚代理服务器的作用,区分正向代理和反向代理的区别,搭建使用Nginx反向搭理和负载均衡,了解Nginx常用配置的说明.即学即用,你还在等什么?一睹为快先了解Nginx的三大功能Nginx 可以作为一台http服务器.可以做网站静态服务器,比如图片服务器,高效,减轻服务器压力.同时它也支持https服务.Nginx 可以配置多台虚拟主机.可以实现在一台服务器虚拟出多个网站效果,省钱.Nginx 最重要的是反向代理,负载均衡.在服务器集群中,Ngin