Nginx之location配置
来源:互联网 发布:庞门正道阿门知乎 编辑:程序博客网 时间:2024/05/19 00:55
location指令可以用于虚拟服务器server部分,并且意味着提供来自客户端的URI或者内部重定向访问。除少数情况外,location也可以被嵌套使用
格式如下
location [modifier] url {……}
或者是命名location
location @name {……}
命名location仅对内部访问重定向,在进入一个location之前他会保留被请求的URI部分,命名location只可以在server级别定义。
比如:
基于域名和端口
server {
listen80; #监听端口
server_name a.com; #监听域名
location/ {
root /var/www/a.com; #根目录定位
index index.html;
}
}
基于IP和端口
server {
listen 8080;
server_name 192.168.1.204;
location / {
root /var/www/html8080;
index index.html;
}
}
一 Location修饰符
nginx不对url做编码,因此请求为/static/20%/aa,可以被规则^~ /static/ /aa匹配到
二 仅用于location的指令
三 过期指令
expires 30d
location ~* .*\.(js|css)?$
{
expires 7d;
}
四 禁止下载文件
location ~*.*\.(zip|rar|exe|msi|iso|gho|mp3|rmvb|mp4|wma|wmv|rm)?$
{
denyall; //禁止这些文件下载,大家可以根据自己的环境来配置
}
五 根目录和首页
root /opt/site/a.example.com
index index.html index.htm
五 匹配顺序
首先匹配 =,其次匹配^~, 其次是按文件中顺序的正则匹配,最后是交给 / 通用匹配。当有匹配成功时候,停止匹配,按当前匹配规则处理请求。
listen 80;
server_name a.example.com
root /opt/site/a.example.com;
location / {
echo"/";
}
location = / {
echo"=/";
}
location = /nginx {
echo"=/nginx";
}
location ~ \.(gif|jpg|png|js|css)$ {
echo"不忽略大小写:staicresources";
}
location ~* \.png$ {
echo"忽略大小写staicresources";
}
location ^~ /static/ {
echo"include static path";
}
[dubbo@dubbo-01 nginx]$ curl http://a.example.com
=/
[dubbo@dubbo-01 nginx]$ curlhttp://a.example.com/nginx
=/nginx
[dubbo@dubbo-01 nginx]$ curlhttp://a.example.com/s/11.jpg
staic resources
[dubbo@dubbo-01 nginx]$ curlhttp://a.example.com/p/12.PNG
忽略大小写staic resources
[dubbo@dubbo-01 nginx]$ curlhttp://a.example.com/static/13.png
include static path- nginx之location配置
- nginx配置之location
- nginx之location配置
- nginx之location配置
- nginx之location配置
- Nginx之location配置
- Nginx 之 Location基础配置 及 Location最佳实践
- nginx之location基础配置及location最佳实践
- Nginx 之 Location基础配置 及 Location最佳实践
- Nginx之Location配置详解(Location匹配顺序)
- Nginx之Location配置详解(Location匹配顺序)
- nginx之location配置---学习笔记
- nginx配置详解之location模块
- Nginx服务器配置之location语法分析
- Nginx location 配置
- Nginx Location配置总结
- Nginx的location配置
- Nginx Location配置总结
- 查询两张表中某一对应字段不相同的…
- mysql删除数据表中的重复记录保留i…
- Incorrect string value…
- mysql根据两张表中某一字段,或者…
- 关于httpclient连接超时的问题一种…
- Nginx之location配置
- 生活中的排队问题
- Spring+springMVC多文件上传(一个…
- RTP/RTCP协议解析
- Unable to compile class for JSP
- Failed to read ca…
- input标签value值中带有引号的处理…
- jquery中json数组转成对象的方法
- springMVC属性值绑定(日期类型转…