===== Nginx =====
https://nginx.org/ru/docs/\\
https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/#
Пути
# www root
/usr/share/nginx/html
# conf
/etc/nginx/nginx.conf
/etc/nginx/conf.d/default.conf
# includes
/etc/nginx/conf.d/*.conf
==== Логи ====
# IP со счётчиком
cat /var/log/nginx/access.log |grep site |grep 200 |awk '{print $1}' |sort |uniq -c > ips.txt
https://www.the-art-of-web.com/system/logs/
==== Блок IP/подсетей ====
nano /etc/nginx/nginx.conf
## Block spammers and other unwanted visitors ##
include /etc/nginx/banlist.conf;
nano /etc/nginx/banlist.conf
deny 1.2.3.4;
deny 91.212.45.0/24;
# тест настроек
nginx -t
# перечитать конфиг (не рвёт соединения)
nginx -s reload
==== Файл-браузер ====
Модуль [[https://nginx.org/ru/docs/http/ngx_http_autoindex_module.html|ngx_http_autoindex_module]]. Аутентификация - [[https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html|ngx_http_auth_basic_module]].
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
server {
# Юникод, чтобы неанглийские символы отображались корректно в браузере
charset UTF-8;
location / {
# Файлы класть сюда в файловую систему
alias /tmp/files/;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
# Аутентификация
auth_basic "Enter your credentials";
auth_basic_user_file /etc/nginx/nginx_htpasswd;
}
}
}
Пароль нужно кодировать с помощью htpasswd (''apk add apache2-utils'') или под Windows с помощью [[https://github.com/shoenig/bcrypt-tool|bcrypt-tool]].
user:$apr1$jSrLMlYc$SqO40GakivRBqlS/5UsXL0
# Файлы будут на хосте по пути /home/user/files, а логин и пароль - в /home/user/nginx_htpasswd
docker run -d --name nginx --rm -p 8080:80 \
-v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro \
-v /home/user/nginx_htpasswd:/etc/nginx/nginx_htpasswd:ro \
-v /home/user/files:/tmp/files \
nginx:alpine
{{.:pasted:20251031-203957.png}}