• Nginx环境的搭建


    源码安装

    不同发行版使用的安装程序都不同,所以官方提供了源代码,我们需要将原代码编译后再安装。

    源程序使用C语言开发,所以需要安装C语言的编译环境。

    安装Nginx环境和第三方支持库

    yum install -y gcc-c++

    yum install -y pcre pcre-devel

    yum install -y zlib zlib-devel

    yum install -y openssl openssl-devel

    Nginx配置

    vim /usr/local/nginx/conf/nginx.conf

        server {
            listen       80;
            server_name  localhost;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
        }

    虚拟主机

    一台物理服务器上运行多个网站。每一个网站都是一个“虚拟”出来的主机。

    如下可定位到两个不同位置的资源去:

     server {
            listen       81;
            server_name  localhost;
    
            location / {
                root   nvpiao;
                index  index.html index.htm;
            }
        }
        
        server {
            listen       82;
            server_name  localhost;
    
            location / {
                root   prepiao;
                index  index.html index.htm;
            }
        }

     基于域名的实现方式

    server {
            listen       80;
            server_name  www.nvpiao.com;
    
            location / {
                root   nvpiao;
                index  index.html index.htm;
            }
        }
        
        server {
            listen       80;
            server_name  www.prepiao.com;
    
            location / {
                root   prepiao;
                index  index.html index.htm;
            }
        }

    反向代理

    配置反向代理时要注意格式,{}内的每一行结束时都需要写“;

    proxy_passproxy代表代理服务器,pass表示这个代理服务器起请求转发的作用。

    upstreamNginx实现负载均衡的一种内置算法名称。

    upstream sina {
            server 192.168.159.251:8280;
        }
    
        server {
            listen       80;
            server_name  www.sina.com;
    
            location / {
                proxy_pass http://sina;
                index  index.html index.htm index.jsp;
            }
        }

    使用默认权重值,多个参与负载均衡的服务器大致平均分配负载

     upstream baidu {
            server 192.168.159.251:8180;
            server 192.168.159.251:8480;
        }

    配置权重值,权重值大的服务器会有较大几率被选中:

    server 192.168.159.251:8180 weight=5;

    负载均衡的其他技术实现:

    Linux virtual server

    官网见:http://www.linuxvirtualserver.org/

  • 相关阅读:
    ACTIVE OBJECT 模式
    Node.js
    WordPress — 突破性能瓶颈,使用 WordPress 站群做 SEO 推广
    HttpRequest.Item 属性 和 HttpRequest.QueryString 属性的区别!
    Regex.Replace 方法的性能!(090625最新修改)
    FACTORY 模式
    Indexof String By Byte[]
    [11]DIP:依赖倒置原则
    C#.Net Winform skin 皮肤 大全(转)
    C# 情缘
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/7607287.html
Copyright © 2020-2023  润新知