Показаны сообщения с ярлыком apache. Показать все сообщения
Показаны сообщения с ярлыком apache. Показать все сообщения

Подсчитать соединения к веб-серверу

netstat -na | awk '$4 ~ /.80/ && ! /.8080/ {print $5}' | cut -d . -f 1,2,3,4 | sort | uniq -c | sort -n

Ограничить доступ по IP в Apache 2.4

    <IfVersion >= 2.4>
        Require all denied
        Require ip 10.11.12.33
        Require ip 188.120.252
    </IfVersion>

strace процессов пользователя в apache mpm-itk

while true; do a=$(ps aux | grep apache | grep usera | awk '{print $2}'); echo "DEBUG pid is "$a; if [ -z $a ] ; then echo -e 'no pid now\n'; else echo "pid is "$a; strace -p $a; fi; sleep 1; done

Включить server-status в CentOS 7

# cat >> /etc/httpd/conf.modules.d/01-status.conf << EOF
<Location /server-status>
SetHandler server-status
Require all granted
</Location>
EOF

# systemctl reload httpd

Если мешает .htaccess сайта - можно сделать вот так на примере wordpress

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

дополнительная авторизация в phpmyadmin

# cat /usr/share/phpMyAdmin/.htaccess

AuthType Basic
AuthName "Private zone"
AuthUserFile /etc/phpMyAdmin/.htpass
require valid-user


# htpasswd -c /etc/phpMyAdmin/.htpass myadmin

# grep AllowOverride /etc/httpd/conf.d/phpmyadmin.conf

# AllowOverride None
AllowOverride AuthConfig

Пересоздаем конфиги httpd в ISPmanager

Если конфиги apache совсем сломались (виртуалхосты), то лечить можно следующим образом

mv /etc/httpd/conf/vhosts /root
mkdir /etc/httpd/conf/vhosts


/usr/local/mgr5/sbin/mgrctl -m ispmgr webreconfigure.initialize shutdown=on
/usr/local/mgr5/sbin/mgrctl -m ispmgr webreconfigure.restore


Документация: Конфигурация web сервера

Сюда же потребовалось увеличивать лимиты иначе упирался в
AH00015: Unable to open logs
AH00015: Unable to open logs


# pwd
/etc/systemd/system/httpd.service.d
# cat limits.conf
[Service]
LimitNOFILE = infinity
LimitMEMLOCK = infinity

systemctl daemon-reload
apachectl start

Apache нагрузка подключения

Просмотр числа подключений на 80 порт

netstat -na --inet | grep ":80\ " | awk '{print $5}' | cut -d":" -f 1 | sort | uniq -c | sort -nr

ss -o '( dport = :http or sport = :http )' | awk '{print $6}' | cut -d : -f 1 | grep -v 'Address' | sort | uniq -c | sort -n

Установка netstat на CentOS 7

yum install net-tools

25 самых активных IP

cat /var/www/httpd-logs/*access.log | awk '{ print $1 ; }' | sort | uniq -c | sort -n -r | head -n 25

25 самых популярных URL

cat /var/www/httpd-logs/*access.log | awk '{ print $7 }' | sort | uniq -c | sort -rn | head -n 25

Закрыть доступ к xmlrpc в wordpress

Закрываем доступ к xmlrpc.php файлу в wordpress

# cat .htaccess
<Files xmlrpc.php>
Order deny,allow
deny from all
</Files>

Кэширование и сжатие в .htaccess для Google PageSpeed

Google PageSpeed https://developers.google.com/speed/pagespeed/insights/ не проходит проверку на сжатие и кэширование

Параметры, которые ему нужны


# cat .htaccess


AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript image/svg+xml

ExpiresActive On
ExpiresDefault "access plus 7 day"

Тюнингуем Apache в CentOS 7

В CentOS 7 apache по дефолту жрет много памяти, делаем так

vi /etc/httpd/conf/httpd.conf

И добавляем в конец файла

Timeout 45
KeepAlive Off

StartServers 2
MinSpareServers 4
MaxSpareServers 8
ServerLimit 50
MaxClients 50
MaxRequestsPerChild 400