nginx相关操作

来源:互联网 发布:薪酬优化方案 编辑:程序博客网 时间:2024/06/05 19:40
  1. nginx信号量与进程控制
    1. term int 迅速的关闭进程 相当于 ./sbin/nginx -s stop
    2. HUP 重新读取配置文件 开启新的工作进程 ./sbin/nginx -s reload
    3. USER1 用于日志分离时使用,重读配置文件 ./sbin/nginx -s reopen
    4. USER2 与 winch(关闭旧进程) 用于nginx升级时配置使用
  2. nginx虚拟主机配置

    1. `user nobody;
      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 {
      // 一般是配置nginx连接的配置
      worker_connections 1024; // 此为 每个子进程的最大允许连接数
      }
      http {
      // 此为配置http服务器的配置
      include mime.types;
      default_type application/octet-stream;

    log_format main ‘remoteaddrremote_user [timelocal]"request”
    access_log logs/access.log main; // main是一种定义好的格式(该日志使用main格式)(远程Ip 等等)

    sendfile on;

    tcp_nopush on;

    keepalive_timeout 0;

    keepalive_timeout 65;

    gzip on;

    server {
    listen 80; //监听端口
    server_name localhost; //服务器域名

    #charset koi8-r;#access_log  logs/host.access.log  main;location / {    root   html;  // 位置,此为相对路径(相对于nginx根目录)    index  index.html index.htm; (缺省目录)}#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;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}
  3. nginx rewrite
    1. 对url进行重写.
    2. 判断语句
    2.1 if 空格( 条件 ) {

            }        2.2  条件中使用的符号  "=" "~"(正则) ~*(不区分大小写的正则) -d-f-e (是否是文件夹,是否是文件,是否存在)        2.3  rewrite的上下午环境是server或者location,所以 可以写在server内 或者 location内
  4. nginx gzip(压缩传输数据)

    1. 浏览器的请求头中, content-encoding:中 可以看到该浏览器支持的压缩方式
    2. gzip on|off 是否开启
      gzip_buffers 32 4k(一般是这个) | 16 8K 压缩在内存中缓冲几块,每块多大
      gzip_comp_level 推荐6
      gzip_disable 正则表达式,什么样的url不压缩
      gzip_min_length 开始压缩的最小长度 200
      gzip_http_version 开始压缩的http协议版本 1.0|1.1
      gzip_proxied 如果请求者是代理服务器,该如何缓存
      gzip_types text/plain application/xml 对那些类型进行压缩(默认就包括html)(mime.types配置文件中有各类型对应的格式)
      gzip_vary on|off 是否传输gzip压缩标志

      注: 二进制文件就不要压缩了..

  5. expires 使用
    1. 图片(长期不易变得数据)等, 当用户在访问后,缓存在用户端.
    2. Context: server, location
    3. 可以使用 s m h d为单位等
    4. 可以在 location中 添加 图片等, 给其缓存加时长

  6. location 定位

    1. 类型 location [=|~|~*|^~] patt{

    }

    1. location = patt {} [精准匹配]
    2. location patt{} [一般匹配]
    3. location ~ patt {} [正则匹配]
    4. 优先级 : 优先匹配 精准匹配
    5. 例子 如果: url=http://域名/,会先精准匹配,然后Url为 http:域名/index.html 在走下一个location,进行跳转 (不纠结这个地方…. )
      location = / {
      root html
      index index.html index.htm
      }
      location /index.html {
      root html
      index index.html index.htm
      }
    6. 正则表达式会覆盖掉其他
  7. 反向代理 和 负载均衡

    1. proxy
    2. upstream
阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小河向前流着改写成拟人句 小河流我愿待在你身旁 弯弯的小河慢慢的流是什么歌 油炸小河虾 小河虾的做法大全家常 小河虾的家常做法 油炸小河虾的做法 干炸小河虾的做法 小河虾怎么养殖 韭菜炒小河虾 炒小河虾的家常做法 清炒小河虾 小河虾怎么吃 小河虾吃什么食物 香辣小河虾的做法 新鲜小河虾怎么做好吃 小河虾的营养价值 小河虾的营养 小河虾怎么做 香酥小河虾 清炒小河虾的做法大全 小河虾图片 如何炒小河虾 炒小河虾的做法 小河虾怎样做好吃 小河虾怎么炸 爆炒小河虾的做法 小河虾怎么洗 小河虾怎么做好吃又简单 小河虾怎么清洗 小河虾怎么养 小河虾怎么炸酥脆 小青虾 小河蚌全文免费阅读 小河蚌明朝梦里 小河蚌全文阅读 小河蚌明朝梦里阅读 小河蚌鲜汤 小河边日村长夫人 星期天小河边玫瑰花编一段话 青青河边