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/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值