server
server {
listen 80 ;
access_log off; #匹配到该server时,不记录日志
return 444; #返回码为444
}
server {
listen 80;
server_name 172.16.31.218;
location / {
try_files $uri $uri/ @mongrel;
}
location @mongrel {
proxy_pass http://127.0.0.1:8080;
}
}
相关解释
server_name的默认值为“”,如果http中没有配置server_name指令,会出如下警告
curl localhost或者curl 127.0.0.1或者curl 本机IP都会返回一个Empty
在配置了server_name后,就只能通过server_name指定的地址访问
try_files $uri $uri/ @mongrel
当用户请求 http://localhost/example 时,这里$uri就是 /example
try_files 到硬盘找这个文件。如果存在名为 /$root/example(其中 $root 是nginx的网页文件根目录,
在这里为/usr/local/nginx/html)的文件,就直接把该文件的内容发送给用户。
如果没有 example 的文件,然后就看 $uri/,增加了一个 /,也就是看有没有名为 /$root/example/ 的目录
如果没有该目录,就发起一个内部子请求给@mongrel
这时会匹配location @mongrel,然后转给 http://127.0.0.1:8080