Internal 导致 nginx 404

来自linux中国网wiki
跳到导航 跳到搜索

ng 配置下下 

 location /websocket/ {
        #internal;
 
        #if ( $http_sec_websocket_protocol = "" ) {
        #       return 400;
        #}


 websocket  404  的原因  


internal
语法:internal 
默认值:no 
使用字段: location 
internal指令指定某个location只能被“内部的”请求调用,外部的调用请求会返回”Not found” (404)
“内部的”是指下列类型:
• 指令error_page重定向的请求。
• ngx_http_ssi_module模块中使用include virtual指令创建的某些子请求。
• ngx_http_rewrite_module模块中使用rewrite指令修改的请求。
一个防止错误页面被用户直接访问的例子:
error_page 404 /404.html;
location  /404.html {
internal;
}


常用场景 
Nginx 的 internal 指令可以用来限制 Web 公共目录下的图片等资源文件被任意用户直接访问。一个明显的使用场景是,对于用户上传的认证图片,属于个人隐私资源,不应该让所有用户都能访问得到,通常只能由管理员审核时查看。

假定需要限制访问的图片的 URL 路径是 /images/auth-pictures/,Nginx 进行如下配置:

location ^~ /images/auth-pictures/ {
  internal;
}
重启 Nginx,直接访问 /images/auth-pictures/ 下的图片,会返回 404:



Nginx internal 指令限制访问图片资源文件


nginx配置location总结及rewrite规则写法