Differences between revisions 2 and 3
Revision 2 as of 2020-01-22 04:18:04
Size: 1809
Comment:
Revision 3 as of 2020-01-22 04:18:28
Size: 1831
Comment:
Deletions are marked like this. Additions are marked like this.
Line 37: Line 37:
To deny requests based on the method, use a conditional statement. To deny requests based on the method, use a conditional statement within a server block.

NGINX

A powerful web server built for multi-threading. Can even be used as a poor man's HAProxySetup.


Configuration

Server blocks

Location blocks

Restricting Access

Access is best restricted by returning error 444 on any restricted requests. (Error 444 means the connection is dropped--the client gets no indication about availability or permission.)

As a good measure, the default server should return deny all requests. This will force requests to carry an external URL.

server {
    listen 80 default_server;
    server_name _;
    return 444;
}

To deny requests for specific files, use a location block.

location ~ ^\.ht {
    return 444;
}

To deny requests based on the method, use a conditional statement within a server block.

if ($request_method !~ ^(GET|HEAD|POST)$ ) {
    return 444;
}

In all circumstances, conditional statements should be the last resort technique. They can be less than intuitive and difficult to debug.


Restricting Referrers

It is sometimes desirable to block referrals.

valid_referers none blocked server_names
               ~example\.com;
if ($invalid_referer) {
    return 403;
}

none matching missing referers ("-"), while blocked matches referers that have been deleted by a firewall.

Literal server names are given with a leading or trailing asterisk (*). Regular expressions are given with a leading tilde (~).


Issues

Do you have referral blocking on? It's possible that you are blocking your own referrals. Whenever the URL is reloaded, the referral header is dropped, allowing the connection.


CategoryRicottone

Nginx (last edited 2023-08-06 18:16:32 by DominicRicottone)