首页 > 窍门 > 科技数码

nginx中针对目录进行IP限制 nginx限制访问ip

来源: 更新时间:2024-06-02 00:09:19
The Beginning

nginx phpmyadmin 针对内网ip用户开放、外网ip用户关闭(在前面的配置中,location ~ ^/目录/使用正则, 优先级高于location /的配置,所以nginx无法对首页进行解析)4ZD育儿早教网

代码如下
4ZD育儿早教网
server {4ZD育儿早教网

listen 80;4ZD育儿早教网

server_name example.com;4ZD育儿早教网

access_log logs/access.log main;4ZD育儿早教网

location / {4ZD育儿早教网

root html;4ZD育儿早教网

index index.php index.html index.htm;4ZD育儿早教网

}4ZD育儿早教网

location ~ ^/phpmyadmin/ {4ZD育儿早教网

allow 192.168.1.0/24;4ZD育儿早教网

deny all;4ZD育儿早教网

location ~ .*.(php|php5)?$ {4ZD育儿早教网

root /var/mailapp/nginx/html;4ZD育儿早教网

fastcgi_pass 127.0.0.1:9000;4ZD育儿早教网

fastcgi_index index.php;4ZD育儿早教网

include fastcgi_params;4ZD育儿早教网

}4ZD育儿早教网

}4ZD育儿早教网

location ~ .*.(php|php5)?$ {4ZD育儿早教网

root /opt/nginx/html;4ZD育儿早教网

fastcgi_pass 127.0.0.1:9000;4ZD育儿早教网

fastcgi_index index.php;4ZD育儿早教网

include fastcgi_params;4ZD育儿早教网

}4ZD育儿早教网

}4ZD育儿早教网

我们也可以这样配置4ZD育儿早教网

代码如下
server {4ZD育儿早教网
listen 80;4ZD育儿早教网
server_name example.com;4ZD育儿早教网
access_log logs/access.log main;4ZD育儿早教网
location / {4ZD育儿早教网
root html;4ZD育儿早教网
index index.php index.html index.htm;4ZD育儿早教网
}4ZD育儿早教网
location ~ ^/download/ {4ZD育儿早教网
allow 192.168.1.0/24;4ZD育儿早教网
deny all;4ZD育儿早教网
index index.php index.do index.html index.htm;4ZD育儿早教网
location ~ .*.(php|php5)?$ {4ZD育儿早教网
root /var/mailapp/nginx/html;4ZD育儿早教网
fastcgi_pass 127.0.0.1:9000;4ZD育儿早教网
fastcgi_index index.php;4ZD育儿早教网
include fastcgi_params;4ZD育儿早教网
}4ZD育儿早教网
}4ZD育儿早教网

location ~ .*.(php|php5)?$ {4ZD育儿早教网
root /opt/nginx/html;4ZD育儿早教网
astcgi_pass 127.0.0.1:9000;4ZD育儿早教网
fastcgi_index index.php;4ZD育儿早教网
include fastcgi_params;4ZD育儿早教网
}

THE END

TAG:用户  优先级  正则  

猜你喜欢

相关文章