Nginx如何显示IP阻止页面?

分享于 

2分钟阅读

互联网

  繁體

问题:

Nginx服务器有一个这样的配置:


server {


 listen 80;


 listen 443 ssl;



 ssl_certificate /etc/nginx/cert/domain.csr;


 ssl_certificate_key /etc/nginx/cert/domain.key;



 server_name ~^(w+).(w+)$ ;



 location / {


 rewrite ^/(.*) /$1 break;


 proxy_pass https://my-app.ondigitalocean.app/ ;


 }



 error_page 500 502 503 504 /50x.html;


 location = /50x.html {


 root /usr/share/nginx/html;


 }



 error_page 444 =200 @unavailable.html;


 location = @unavailable.html {


 #root /usr/share/nginx/html;


 proxy_pass https://myapp.ondigitalocean.app/unavailable.html;


 allow all;


 }



 if ($allowed_country = no) {


 return 444;


 }


}



工作正常,但我无法获得在远程服务器unavailable.html上分配的(请参见proxy_pass )页


 [error] 20#20: *1 could not find named location "@unavailable.html", client: 172.17.0.1, server: ~^(w+).(w+)$




答案1:


location [ = | ~ | ~* | ^~ ] uri { ... }


location @name { ... }



然后,可以将传递给上游的路径强制为所需的路径:


location @unavailable.html {


 rewrite ^ /unavailable.html break;


 proxy_pass https://myapp.ondigitalocean.app;


}



Nginx文档实际上建议不要将URI放入这里的proxy_pass指令中;


显示  Block  Nginx  Blocked  
相关文章