Nginx 安装配置

news/2024/7/9 17:01:20 标签: 运维, epoll

为什么80%的码农都做不了架构师?>>>   hot3.png

一、) 安装Nginx
1.) 安装
Nginx发音为[engine x],是由俄罗斯人Igor Sysoev建立的项目,基于BSD许可。据说他当初是F5的成员之一,英文主页:http://nginx.net。俄罗斯的一些大网站已经使用它超过两年多了,一直表现不凡。

在这里,需要说明一下,由于Nginx的配置文件中我想用到正则,所以需要 pcre 模块的支持。

可以到这里下载一个http://www.pcre.org/

解压再cp到和nginx同一个目录上
Nginx的编译参数如下:

tar zxvf nginx-0.5.33.tar.gz
cd nginx-0.5.33/
./configure --prefix=/usr/local/nginx --with-http_stub_status_module  --with-pcre=../pcre-6.6
make && make install

2.) 修改配置文件 /usr/local/nginx/conf/nginx.conf
以下是我的 nginx.conf 内容,仅供参考:

#运行用户
user  nobody nobody;

#启动进程 一般和cpu数对等,压力大的也可以调高点
worker_processes  2;

#全局错误日志及PID文件
error_log  logs/error.log notice;
pid        logs/nginx.pid;

#工作模式及连接数上限
events {
        use epoll;
        worker_connections      1024;
}

#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
        #设定mime类型
        include       conf/mime.types;
        default_type  application/octet-stream;

        #设定日志格式
        log_format main         '$remote_addr - $remote_user [$time_local] '
                                                '"$request" $status $bytes_sent '
                                                '"$http_referer" "$http_user_agent" '
                                                '"$gzip_ratio"';

        log_format download '$remote_addr - $remote_user [$time_local] '
                                                '"$request" $status $bytes_sent '
                                                '"$http_referer" "$http_user_agent" '
                                                '"$http_range" "$sent_http_content_range"';

        #设定请求缓冲
        client_header_buffer_size    1k;
        large_client_header_buffers  4 4k;

        #开启gzip模块
        gzip on;
        gzip_min_length  1100;
        gzip_buffers     4 8k;
        gzip_types       text/plain;

        output_buffers   1 32k;
        postpone_output  1460;

        #设定access log
        access_log  logs/access.log  main;

        client_header_timeout  3m;
        client_body_timeout    3m;
        send_timeout           3m;

        sendfile                on;
        tcp_nopush              on;
        tcp_nodelay             on;

        keepalive_timeout  65;

        #设定负载均衡的服务器列表
        upstream mysvr {
                #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;
        }

        #设定虚拟主机
        server {
                listen          80;
                server_name     192.168.8.1 www.yejr.com;

                charset gb2312;

                #设定本虚拟主机的访问日志
                access_log  logs/www.yejr.com.access.log  main;

                #如果访问 /img/*, /js/*, /css/* 资源,则直接取本地文件,不通过squid
                #如果这些文件较多,不推荐这种方式,因为通过squid的缓存效果更好
                location ~ ^/(img|js|css)/  {
                        root    /data3/Html;
                        expires 24h;
                }

                #对 "/" 启用负载均衡
                location / {
                        proxy_pass      http://mysvr;

                        proxy_redirect          off;
                        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   90;
                        proxy_send_timeout      90;
                        proxy_read_timeout      90;
                        proxy_buffer_size       4k;
                        proxy_buffers           4 32k;
                        proxy_busy_buffers_size 64k;
                        proxy_temp_file_write_size 64k;
                }

                #设定查看Nginx状态的地址
                location /NginxStatus {
                        stub_status             on;
                        access_log              on;
                        auth_basic              "NginxStatus";
                        auth_basic_user_file  conf/htpasswd;
                }
        }
}

运行以下命令检测配置文件是否无误:

  如果没有报错,那么就可以开始运行Nginx了,执行以下命令即可:
  备注:conf/htpasswd 文件的内容用 apache 提供的 htpasswd 工具来产生即可,内容大致如下:
  3.) 查看 Nginx 运行状态
  输入地址 http://192.168.8.1/NginxStatus/,输入验证帐号密码,即可看到类似如下内容:
Active connections: 328
server accepts handled requests
9309 8982 28890
Reading: 1 Writing: 3 Waiting: 324


  第一行表示目前活跃的连接数
  第三行的第三个数字表示Nginx运行到当前时间接受到的总请求数,如果快达到了上限,就需要加大上限值了。
  第四行是当前处理的请求数

转载于:https://my.oschina.net/javagg/blog/3317


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

相关文章

Knapsack problem FZU - 2214 背包

一、内容 Given a set of n items, each with a weight w[i] and a value v[i], determine a way to choose the items into a knapsack so that the total weight is less than or equal to a given limit B and the total value is as large as possible. Find the maximum …

Cash Machine POJ - 1276 多重背包

一、内容 A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k1,N, and for each denomination Dk the machine h…

《国富论》各译本之粗略比较

本文转自:http://fanthy.blogbus.com/logs/41908827.html国富论最早由翻译家严复引入国内,书名是《原富》,这个版本很难找到了。目前国内比较多见的有8种译本。一是较早的商务印书馆版本,1930年由郭大力、王亚南译(王亚…

oracle错误39087,关于Oracle使用EXPDP时遇到的几个错误 | 学步园

了解了EXPDP的使用后,然后过了一阵子,开始对批量导出进行运用,结果发现了一系列的问题。首先创建好逻辑目录和操作系统对应的物理目录后,开始执行下面的导出语句expdp username/psw dumpfilebigdata.dmp logfileexplog.log direct…

C#接口和抽象类技术特点

一、C#抽象类: C#抽象类是特殊的类,只是不能被实例化;除此以外,具有类的其他特性;重要的是抽象类可以包括抽象方法,这是普通类所不能的。抽象方法只能声明于抽象类中,且不包含任何实现&#xff…

I love sneakers! HDU - 3033 分组背包变形

一、内容 After months of hard working, Iserlohn finally wins awesome amount of scholarship. As a great zealot of sneakers, he decides to spend all his money on them in a sneaker store.There are several brands of sneakers that Iserlohn wants to collect, suc…

oracle中查询曾报错的sql,ibatis动态多条件查询及模糊查询(oracle,mysql,sql)

.htmliBatis 开发指南告诉我们,当 Person 对象的 name 属性不为 null 时启用 name 查询条件在映射文件 person.xml 中的配置为select id as id,name as name,passwd as passwd from person(name like #name#)select id as id,name as name,passwd as passwd from pe…

Mysql参数详解(二):ft_min_word_len

◆ft_min_word_len从Mysql 4.0 开始就支持全文索引功能,但是 Mysql 默认的最小索引长度是 4。如果是英文默认值是比较合理的,但是中文绝大部分词都是2个字符,这就导致小于4个字的词都不能被索引,全文索引功能就形同虚设了。为什么…