nginx企业级优化

配置nginx隐藏版本号

  • 获取网站信息

    curl -I http://192.168.200.18
    server:nginx/1.8.0  #网站应用以及版本号
    
  • 修改源码包

    #安装nginx,直到解压到目录步骤中
    cd /usr/src/nginx-1.14.2/
    vim src/core/nginx.h
      #define NGINX_VERSION      "1.11.1"    #版本号
      #define NGINX_VER          "apche/" NGINX_VERSION    #应用名称
    #编译安装
    ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install
    #启动查看
    curl -I http://192.168.200.19
    server:apche/1.11.1
    
  • 修改配置文件

    vim /usr/local/nginx/conf/nginx.conf
    28  server_tokens  off;  #添加隐藏版本配置
    #启动查看
    curl -I http://192.168.200.19
    server:nginx
    

修改nginx的用户和组

  • 在编译安装是指定
    ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install

  • 修改配置文件

    在nginx.conf中添加user  nginx nginx;
    

配置页面缓存时间

  • nginx将页面放回客户端时,设置缓存页面时间,以方便客户在日后进行统一操作时,方便返回。一般只针对静态页面。
    #配置方法,在http段,server段,location段配置过期参数
    location ~ .(gif|jpg|jpeg|gng|bmp|ico)$ {
                  expires 1d;
          }
     #页面中以上述结尾的文件缓存一天
          location ~ .*.(js|css)$ {
                  expires 1h;
          }
      #页面中以上述结尾的文件缓存一小时
    
    #重启nginx
    自行检测添加图片fiddler抓包日志软件
    

nginx日志切割

  • nginx日志
    [root@hostlocal html]# ls -l   /usr/local/nginx/logs/
    总用量 96
    -rw-r--r--. 1 root root 56896 9月  15 18:50 access.log
    -rw-r--r--. 1 root root 36459 9月  15 18:46 error.log
    -rw-r--r--. 1 root root     5 9月  15 18:32 nginx.pid
    
    
  • datetime命令
    
    
原文地址:https://www.cnblogs.com/wml3030/p/15292300.html