美文网首页WEB服务
nginx「配置文件通用语法」

nginx「配置文件通用语法」

作者: 木云先森 | 来源:发表于2020-01-31 16:58 被阅读0次

    简要说明nginx的大的配置逻辑和方式,具体的细节,会有后续的章节做说明。
    下面列举7个配置的原则

    1. 配置文件由指令与指令块构成
    2. 每条指令以分号(;)结尾,指令与参数间以空格符号分割,多个参数之间也是如此
    3. 指令块以大括号({})讲多条指令组织在一起
    4. 使用#号添加注释
    5. 使用$符号使用变量
    6. 部分指令的参数支持正则表达式
    7. include语句允许组合多个配置文件提升可维护性

    下面说明具体的配置时间单位

    ms -- millseconds   
    s  -- seconds
    m  -- minutes
    h  -- hours
    d  -- days
    w  -- weeks
    M  --mouths
    y  -- years
    

    下面为具体的空间单位

    缺省 -- bytes
    k/K -- kilobytes
    m/M -- megabytes
    g/G -- gigabytes
    

    下面为对应的HTTP的配置指令块

    http server(域名) location(url相关) upstream(上游服务相关)
    

    具体的实例,这也是我本地的nginx.cof的一个配置的实例

    http {
          include       mime.types;
          default_type  application/octet-stream; 
          access_log  /Users/muyun/nginx/log/access.log  main;
    
          server {
              listen       8020;
              server_name  localhost;
     
              location / {
                  root   /Users/muyun/nginx/www;
                  #alias   /Users/muyun/nginx/www/;
                  index  index.html index.htm index.php;
              }
     
              #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;
              }
    
          }
    
    

    相关文章

      网友评论

        本文标题:nginx「配置文件通用语法」

        本文链接:https://www.haomeiwen.com/subject/yvigthtx.html