1.conf
location / {
deny all;
allow 127.0.0.1;
}
他会从上到下依次检验,如果deny全部拦截,allow就都不允许。
1.精确匹配
localtion =/ img {
allow all;
}
设置访问权限目录
2.正则表达式文件
localtion ~\.php$ {
deny all;
}
3.根据端口号设置主机
`新建server文件``
sever{
listen 8001;
server_name localhost;
root /usr/share/nginx/html/html8001;
index index.html;
}
4.根据域名设置虚拟主机
修改server_name
5.反向代理
sever{
listen 8001;
server_name localhost;
location / {
proxy_pass 111.111.11.111;
}
}
6.适配PC或移动设备
mkdir PC
mkdir mobile
建立config配置文件
sever{
listen 8001;
server_name localhost;
location / {
root /usr/share/nginx/pc;
if($http_user_agent ~* 'Android|webOS|iPhone|iPod|BlackBerry'){
root /usr/share/nginx/mobile;
}
index index.html;
}
}
7.Gzip压缩
nginx.conf
http {
gzip on;
gzip_types text/plain application/javascript text/css;
}