web优化之nginx优化<七>

2.更改nginx的默认用户


    这里我们接着web之nginx优化<->继续分析使用普通用户的重要性。

    在高标准环境下尽量不使用root,尽量使用普通用户,这样外部人员提权也提不到root用户。搭建服务的时候就用普通用户搭建,生产环境下最好不要随便用root用户。

 1)让nginx服务使用普通用户

    ・root用户跑master进程的隐患:

      a.管理权限必须是root,这就使得最小化分配权限原则遇到难题

      b.使用root跑nginx服务,一旦网站出问题,用户很容易获得服务的root权限

    ・nginx服务降权解决方案(来自支付宝之前的方案)

      给nginx降权,nginx用户管理nginx服务,给开发普通用户权限

    ・用普通用户跑不能用特权端口如8080

worker_processes  4;
worker_cpu_affinity 0001 0010 0100 1000;
worker_rlimit_nofile 65535;
error_log  /home/inca/logs/error.log;
user inca inca;
pid        /home/inca/logs/nginx.pid;
events {
    use epoll;
    worker_connections  10240;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    #web.fei fa daolian..............
    server {
        listen       8080;
        server_name  www.etiantian.org;
        root   /home/inca/www;
        location / {
            index  index.php index.html index.htm;
                }
         access_log  /home/inca/logs/web_blog_access.log  main;
           }
}
[root@www ~]# useradd inca
[root@www ~]# su - inca
[inca@www ~]$ pwd
/home/inca
[inca@www ~]$ mkdir conf logs www
[inca@www ~]$ cp /application/nginx/conf/mime.types ~/conf/
[inca@www ~]$ echo inca >www/index.html
 /application/nginx/sbin/nginx -c /home/inca/conf/nginx.conf  &>/dev/null


20.限制IP 

Nginx的配置文件如下

[root@oldboy ~]# cat /application/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    limit_conn_zone $binary_remote_addr zone=addr:10m;

    server {
        listen       80;
        server_name   www.etiantian.org;
        location / {
            root   html;
            index  index.html index.htm;
            limit_conn addr 1; #<==限制单IP的并发连接为1
        }
    }
}
 limit_conn_zone $server_name zone=perserver:10m;

ngx_http_limit_req_module模块用于限制每个IP访问每个定义key的请求速率。 

wKioL1YrqYjScDllAAOiGjiwaRk111.jpg


更多优化见http://7826443.blog.51cto.com/7816443/1705051

nginx的变量大全:http://nginx.org/en/docs/varindex.html

你可能感兴趣的:(开发,用户,master,支付宝,解决方案)