Skip to content

Latest commit

 

History

History

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Configuration

listen

server {
  listen 80 # 0.0.0.0:80
  # or
  listen 80 8080
  # or
  listen 127.0.0.1:1234
}

host

server {
  host example.com    # Domain name
  # or
  host *.example.com  # Wildcard
}

root

server {
  root /root/www
  # or
  root ./www
}

https

server {
  host example.com
  https {
    key  /root/ssl.key
    cert /root/ssl.pem
  }
}

echo

server {
  echo Hello world
  # or
  echo Hello, $`path`
}

file

server {
  file ./www/index.html
}

rewrite

server {
  rewrite /example  # Default 302
  # or
  rewrite {
    location https://$`header_host`$`path`
    status 301
  }
}

directory

server {
  directory on | off | [option]
  # Display creation time
  directory {
    time on | off | %Y-%m-%d %H:%M
  }
  # Display file size
  directory {
    size on | off
  }
}

compress

server {
  compress on
  # or
  compress {
    # Optional value: 'auto' 'gzip' 'deflate' 'br'
    mode gzip
    # Optional value: 'default' 'fastest' 'best'
    level default
    # Which files are compressed, default: 'html' 'css' 'js' 'json' 'png'
    extension css js
  }
  # or
  compress {
    # Set compression priority
    mode br gzip auto
  }
}

index

Index file, default: index.html.

server {
  index index.html index.htm
}

header

server {
  header {
    Access-Control-Allow-Origin *
    Set-Cookie 12345
  }
}

method

Method of allowing requests, default: GET HEAD.

server {
  method POST PUT
}

auth

HTTP authentication.

server {
  auth {
    user 123
    password 456
  }
}

try

server {
  try $`path`.html index.html
}

error

Custom error page.

If you use relative path, then you must set the root option.

server {
  error {
    403 ./403.html
    404 ./404.html
    500 ./500.html
    502 ./502.html
    504 ./504.html
  }
}

proxy

server {
  proxy {
    url http://example.com  # Proxy address.
    method GET              # Change the method of the proxy.
    header {                # Header in proxy request.
      key value
    }
  }
  # or
  proxy {
    url http://example.com$`path`$`query`
  }
}

log

server {
  log /var/log/www.log
  # or
  log {
    mode stdout  # stdout | file
  }
  # or
  log {
    file /var/log/www.log
    format $`path` $`header_host`
  }
}

ip

Allow and deny clients from specified IP(s).

server {
  ip {
    allow 127.0.0.1 192.168.0.*
    deny 172.17.*.*
  }
}

Location

Modifier

  • @ Matching with glob expression.
  • ~ Matching using regular expression.
  • ^ Matching the start of a location with a string.
  • $ Matching the end of a location with a string.
server {
  @ /public {
    directory on
  }
  @ /private/** {
    auth {
      user 123
      password 456
    }
  }
  ~ ^/[1-9]{10}$ {
    echo regex
  }
  ^ /start {
    echo start
  }
  $ .png {
    echo end
  }
}

Variable

Built-in variables can be used in echo, rewrite, header and proxy.

$`path`
$`query`
$`method`
$`version`
$`time`
$`query_NAME`
$`header_NAME`
server {
  echo Hello $`path`, $`header_host`
}