公司网站后端需要对外屏蔽管理后端, location里添加deny 和allow时 ,deny ip为403,allow ip报错404。
需要在需要执行该功能的proxy_pass
每个块中放置一个指令。location
这些proxy_set_header
指令可以从外部块继承。
在location里添加proxy_pass http://web;
server {
server_name example.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header CF-Connecting-IP $http_cf_connecting_ip;
proxy_set_header CF-Ipcountry $http_cf_ipcountry;
proxy_set_header CF-Ray $http_cf_ray;
proxy_set_header Cf-Visitor $http_cf_visitor;
location ~* /(file.php|directory) {
allow 1.1.1.10;
allow 2.2.2.11;
deny all;
proxy_pass http://web;
}
location / {
proxy_pass http://web;
}
}