NGINX拒否ルールはいつ適用されますか?

NGINX拒否ルールはいつ適用されますか?

server 80以下を含むreturnディレクティブがありますallow/deny

...
server {

    server_name    dev.monitor.domain.ms;
    listen         80;

    allow 194.***.45;
    allow 37.***.130;
    deny  all;

    return 301 https://dev.monitor.domain.ms$request_uri;
}
...

.serverlisten 443

したがって、ここでreturn 301質問がアクセスが許可されていないIPに対してもここで機能するのはなぜですか?

最後に - 実際に接続できないのでallow/deny動作しますが...

例:

$ curl -vL dev.monitor.domain.ms
* About to connect() to dev.monitor.domain.ms port 80 (#0)
...
< HTTP/1.1 301 Moved Permanently
 ...
< Location: https://dev.monitor.domain.ms/
...
* Issue another request to this URL: 'https://dev.monitor.domain.ms/'                                                                                                                                                                            
* About to connect() to dev.monitor.domain.ms port 443 (#1)                                                                                                                                                                                      
*   Trying 40.***.***.237... Connection timed out                                                                                                                                                                                              
* couldn't connect to host                                                                                                                                                                                                                    
* Closing connection #1                                                                                                                                                                                                                       
curl: (7) couldn't connect to host

allow/denyブロックに追加しても同じですhttp {}。それでは、いつ、どこでこれらの制限を確認する必要がありますか?

ngx_http_access_module文書はこれについて何も言及していません。

ベストアンサー1

denyNginxのすべての対応する場所に適用されます。
場所を定義していないため適用されません。

リダイレクトを次の場所に配置します。

location / {
    return 301 https://dev.monitor.domain.ms$request_uri;
}

ただし、これは指定されたホストに対してセキュリティを提供しません。
それでもHTTPSホスト内で権限を確認する必要があります。

おすすめ記事