nginx deny location blocks

 

 

 


 

/etc/nginx/templates/deny_blocks.conf

# Deny 所有以 "." 開始的 files/folders
# 如 .git, .htaccess, .htpasswd, .DS_Store (Mac), etc...
location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
}

# git folder
location ~ /\.git {
    deny all;
    access_log off;
    log_not_found off;
}

# python code
location ~* /.+\.(py|pyc)$ {
    deny all;
access_log off;
log_not_found off;
    return 404;
}

# .env
location ~* /\.env$ {
    deny all;
    access_log off;
    log_not_found off;
}

# Deny yaml, twig, markdown, ini file access
location ~* /.+\.(markdown|md|twig|yaml|yml|ini)$ {
    deny all;
    access_log off;
    log_not_found off;
}

# Deny all meta files
location ~* (README|LICENSE|INSTALL|UPGRADING)$ {
    deny all;
    access_log off;
    log_not_found off;
}

# Deny all composer files
location ~* composer\. {
    deny all;
    access_log off;
    log_not_found off;
}

 

/etc/nginx/vhosts/webservices.conf

server {
    ...
    # deny_blocks
    include     /etc/nginx/templates/deny_blocks.conf;
}

 

Creative Commons license icon Creative Commons license icon