加入收藏 | 设为首页 | 会员中心 | 我要投稿 徐州站长网 (https://www.0516zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Linux下搭建Nginx环境

发布时间:2016-09-22 04:21:37 所属栏目:Linux 来源:站长网
导读:一、) 安装Nginx 1.) 安装 Nginx发音为[engine x],是由俄罗斯人Igor Sysoev建立的项目,基于BSD许可。据说他当初是F5的成员之一,英文主页:http://nginx.net。

#设定负载均衡的服务器列表

upstream ixdba{

#weigth参数表示权值,权值越高被分配到的几率越大

#本机上的Squid开启3128端口

server 192.168.8.1:3128 weight=5;

server 192.168.8.2:80 weight=1;

server 192.168.8.3:80 weight=6;

}

#下面是配置虚拟主机

   include    /usr/local/nginx/conf/proxy.conf;

include    /usr/local/nginx/conf/vhosts/www.test.com.conf;

3)虚拟主机配置文件详解

由于虚拟主机分别有一个文件来指定,下面举例某个虚拟主机的配置如下:

[root@oracle132 vhosts]#

vi /usr/local/nginx/conf/vhosts/www.test.com.conf;

server {

listen       80; #虚拟主机使用端口

server_name www.test.com; #虚拟主机访问域名

charset UTF-8; #设定nginx默认字符编码

#access_log logs/host.access.log main;

#所有jpg格式的图片都有nginx来处理

location ~ .jpg$ {

       root    /cicro/cws3/vhosts/www.test.com/ROOT;

       expires 30d;

}

#所有gif格式的图片都有nginx来处理

location ~ .gif$ {

       root    /cicro/cws3/vhosts/www.test.com/ROOT;

       expires 30d;

}

# upload和html下所有文件都有nginx来处理

location ~ ^/(upload|html)/  {

       root    /cicro/cws3/vhosts/www.test.com/ROOT;

       expires 30d;

}

#除去上面的文件,剩下的所有都代理给http://127.0.0.1:8009来访问

location / {

   root   /cicro/cws3/vhosts/www.test.com/ROOT;

   index  index.html;

   proxy_pass http://127.0.0.1:8009;

}

#设定查看Nginx状态的地址

location /NginxStatus {

               access_log              on;

               auth_basic              "NginxStatus";

auth_basic_user_file    ../htpasswd;

}

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

}

}

(编辑:徐州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读