02-Nginx反向代理和负载均衡

news/2024/7/10 0:16:48 标签: nginx, 负载均衡, 代理服务器

正向代理

表示确定服务器的地址,比如翻墙。

反向代理

表示不确定服务器地址,比如服务器集群

负载均衡">负载均衡

一台服务器压力比较大,会奔溃,通过代理服务器管理集群分担压力。

#声明用户为nobody
user nobody;

#开启nginx工作进程数,一般为1
#可以通过ps -ef | grep nginx 查看到有4个工作进程
worker_processes 4;

#设置并发数
events{
        #设置最大并发数
        worker_connections 1024;
}


http{
        #设置待负载均衡服务器列表
        upstream mypro {
                #百度
                server 119.75.213.61;
                #京东
                server 124.192.136.131;
                #万网
                server 199.59.242.150;
        }

        #nginx服务器
        server{
                #监听网站端口
                listen 8080;
                #nginx根目录
                location / {
                        #做负载均衡选择哪个服务器列表
                        proxy_pass http://mypro;
                }
        }
}
~

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

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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;
    #    }
    #}
    include servers/*;
}

http://www.niftyadmin.cn/n/1852399.html

相关文章

修改vcenter的Administrator@vsphere.local密码

vsphere 忘记vcenter的Administratorvsphere.local密码的解决办法 1、cd c:\Program Files\VMware\Infrastructure\VMware\CIS\vmdird这个要看你安装的路径。 2、执行如下命令: vdcadmintool.exe 3、在弹出的如下选单里,选择 3 Please select: 0.…

写给计算机专业的学生

一、给计算机专业的同学 1. 首先请你热爱这个专业。只有这样,你才会从抽象的理论中找到实实在在的快乐。如果你不热爱她,或者只因为这是个热门专业,那么极 力要求你放弃这个专业,因为计算机是一把双刃剑,学好了你会飞…

我是如何利用一个只有500人的QQ通过人性的弱点来变现的

引流高手有很多,大家也都不缺泛流量,松哥博客引流的方式数不完,但是教大家变现的无非就是男性用户转男性用品,女性用户转女性用品,说实话,很LOW,跟没说一样。十万好友又怎样,产品/服…

Windows Management Instrumentation

简称WMI,WMIC提供了简单的Windows Management Instrumentation(WMI)命令行界面,这样用户可利用WMI来管理运行Microsoft Windows的计算机,WMIC与现有命令行程序和实用程序命令相互操作,且很容易通过脚本或其…

POJ 3304 Segments(判断直线与线段是否相交)

http://poj.org/problem?id3304 等价于是否存在一条直线穿过所有线段 判断直线与线段是否相交: 首先用两点p1,p2确定了一条直线 在用p1,p2分别与计算线段两个端点计算叉乘即可 ,叉乘之积>0就说明线段两端点在直线的同侧,也就是直线不经过…

百度快速排名的七大谎言

关于快速排名网上有很多相关资料,但是如果你按照网上的那些说法去操作的话你会发现貌似都没有效果!是的,要承认一点:能研发出快速排名的人不会把核心技术公布出来。网上的那些关于快速排名的资料只不过是那些没用实战过的人的猜测而已&#x…

我工作的第一家公司倒闭了...

2007年,恍惚了4年的我,走出了校门,回到了家乡。没有工作的我,忙碌了两个月后终于接到一份面试通知,原本不抱希望的我抱着试一试的心态,带着简历来到xxx公司。很意外,面试我的不是职业的hr&#…

内容营销的21条黄金法则

在“内容为王”的移动互联网时代,营销策略中的内容营销已经被加冕为王。对于创业者和创新企业来说,SEM(搜索引擎营销)、粉丝经济、公关等等手段尚不可形成规模,现阶段唯一能做好的,就是以内容为王道做好营销。那么,有什…