Nginx调度器

vim   /etc/rc.local                    //开机自动启动nginx程序的脚本,里面添加nginx(/usr/local/nginx/sbin/nginx)


部署实施后端Web服务器

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

upstream   服务器池名 {

    ip_hash;                                                 //设置相同客户端访问相同web服务器

    server  服务器ip1:80  weight=2;                               //weight设置服务器权重值,默认值为1

    server  服务器ip2:80 max_fails=1 fail_timeout=10 down;        //max_fails设置最大失败次数,fail_timeout设置超时时间,单位为秒,down是指此服务无法正常使用。

    ................

    }

location  / {

扫描二维码关注公众号,回复: 185180 查看本文章

proxy_pass  http://服务器池名;            //在此位置添加跳转至服务器池,自身是代理服务器不需要做nginx服务器需要做的事情

}


Nginx的TCP/UDP调度器

./configure     \

--user=nginx                                                //指定nginx安装所属主为nginx

--group=nginx                                               //指定nginx安装所属组为nginx

--with-http_ssl_module                                      //开启ssl加密功能

--with-stream                                               //--with-stream开启四层反向代理功能

make  && make install                                      //编译  安装

vim  /usr/local/nginx/conf/nginx.conf                          //修改主配置文件,在新安装的nginx环境下。

................

worker_connections  1024;

}

stream {

        upstream  myssh {
                server  192.168.2.100:22;                        //后端服务器的ip和端口号;
                server  192.168.2.200:22;
                        }
        server {
                listen 12345;                                     //nginx监听的端口;
                proxy_pass myssh;
                }
        }
worker_processes  1;                                            //进程  与cpu核心数一致
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
#
      *                   soft        nofile         100000

http {

................................


ssh -p 12345 192.168.4.5                                      //ssh -p 指定端口号    ssh  nginx代理服务器  会直接连接后端服务器。


优化Nginx并发量

vim  /usr/loca/nginx/conf/nginx.conf

#user  nobody;

    worker_connections  65535;                                   //并发量默认值为1024,1024*cpu核数


//linux默认最大打开文件数量为1024

ulimit -a                                                        //查看所有属性值

ulimit -Hn  1000000                                              //设置硬限制(临时规则)

ulimit -Sn   1000000                                             //设置软限制(临时规则)

vim  /etc/security/limits.conf                                     //改配置文件设置永久

...............

#<domain>      <type>  <item>         <value>              //对谁设置  设置软限制还是硬限制   限制什么    数量

      *                   hard       nofile         100000



优化Nginx数据包头缓存

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

.................

http {

client_header_buffer_size 1k;                                //默认请求包头信息的缓存    

large_client_header_buffers 4 4k;                              //大请求包头部信息的缓存个数与容量


浏览器本地缓存静态数据

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

................

location / {

root html;

index index.html index.htm;

}

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {                          

expires        30d;                                                              //定义客户端缓存时间为30天

}


自定义报错页面

200        一切正常

301        永久重定向

302        临时重定向

401        用户或密码错误

403        禁止访问(客户端ip地址被拒绝)

404        未找到(不存在)

414        URI太长(请求地址栏太长)

500        服务器内部错误

502        Bad Gateway

error_page  404              /404.html;        //出现404报错则显示404.html内的内



如何查看服务器状态信息

./configure \

> --with-http_ssl_module                              //开启SSL加密功能

> --with-strea                                               //开启TCP/UDP代理模块

> --with-http_stub_status_module                //开启status状态页面

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

… …

location /status {

stub_status on;

}

......


curl http://192.168.4.5/status

Active connections: 1

server accepts handled requests

10 10 3

Reading: 0 Writing: 1 Waiting: 0

Active connections:当前活动的连接数量。

Accepts:已经接受客户端的连接总数量。

Handled:已经处理客户端的连接总数量(一般与accepts一致,除非服务器限制了连接数量)。

Requests:客户端发送的请求数量。

Reading:当前服务器正在读取客户端请求头的数量。

Writing:当前服务器正在写响应信息的数量。

Waiting:当前多少客户端在等待服务器的响应。



对页面进行压缩处理

http {

.. ..

gzip on;                            //开启压缩

gzip_min_length 1000;                //小文件不压缩

gzip_comp_level 4;                //压缩比率

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

                                    //对特定文件压缩,类型参考mime.types

.. ..

}


猜你喜欢

转载自blog.csdn.net/jon_stark/article/details/80227757