跳到主要內容

Apache, PHP 7.3 and MySQL on CentOS 7.6

在裝機之前有幾件事情要先確認


  1. hostname 設定不可為 SSL 憑證相同,可以隨便取名
  2. root 密碼一定要修改,透過密碼產生器配置超過 20 碼長度


預設環境為 Apache, PHP 7.3 and MySQL on CentOS 7.6
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/

安裝過程中會出現 firewall 找不到功能指令的錯誤,請參考下篇進行操作
https://bobcares.com/blog/firewall-cmd-command-not-found/

安裝完畢後,請立即修正 ssh 的登入 port 建議使用 10000 以上,修改請參考

Denyhosts攻擊

  1. Linux各平台現在基本上都可以直接安裝Denyhosts了,直接運行命令安裝


1
yum install denyhosts

  1. 安裝好了Denyhosts,默認的配置基本上就可以防禦一定的暴力攻擊了,/etc/hosts.deny文件裡保存了被屏蔽的記錄。
  2. 如果你要自定義Denyhosts的相關配置,執行:vi /etc/denyhosts.conf,相關參數的說明可以自行搜索,一般用戶默認即可。
https://i-square.github.io/post/%E5%A2%9E%E5%BC%BAVPS%E5%AE%89%E5%85%A8%E6%80%A7%E7%9A%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/

為了避免 SYN 洪水攻擊,請參考下列文章進行修正
對於SYN flood攻擊,調整下面三個參數就可以防範絕大部分的攻擊了。
方式1:減少SYN-ACK數據包的重發次數(默認是5次):
sysctl -w net.ipv4.tcp_synack_retries=3
sysctl -w net.ipv4.tcp_syn_retries=3
方式2:使用SYN Cookie技術:
sysctl -w net.ipv4.tcp_syncookies=1
方式3:增加backlog隊列(默認是1024):
sysctl -w net.ipv4.tcp_max_syn_backlog=2048
方式4:限制SYN並發數:
iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT --limit 1/s

貌似現在的內核默認都是開啟tcp_syncookies的。
其他:使用DDoS deflate腳本自動屏蔽攻擊ip 
https://www.cnblogs.com/sunsky303/p/11811097.html

安裝 csf 防火牆
https://www.howtoforge.com/tutorial/install-and-configure-csf-config-server-firewall-on-centos-7/

留言

這個網誌中的熱門文章

安全性修正 - Apache: Disable the HTTP TRACE Method

Apache: Disable the HTTP TRACE Method 編輯 apache 的系統檔( Apache 1.3.34、2.0.55 以後版本) $ vi /etc/httpd/conf/httpd.conf 最下方找空白的地方加入 TraceEnable off 重啟 apache 服務 $ service httpd restart 測試是否正常關閉 $ curl -i -X TRACE http://www._website_.com/ HTTP/1.1 405 Method Not Allowed Date: Wed, 13 Feb 2013 14:30:32 GMT Server: Apache/2.2.15 (CentOS) Allow: Content-Length: 223 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>405 Method Not Allowed</title> </head><body> <h1>Method Not Allowed</h1> <p>The requested method TRACE is not allowed for the URL /.</p> </body></html>

SSL Labs A+ 2021

可以先參考這篇進行修正,把內容放入 ssl.conf 裡基本上就有 A+  https://blog.camilord.com/2021/02/23/ssllabs-com-how-to-get-a-on-ssl-server-test-as-of-feb-2021/ 再搭配這篇調整 https://zurgl.com/how-to-get-a-100-score-on-ssl-labs-red-hat-centos-7-x-apache-lets-encrypt/

安全性修正 - 調整 SSL 安全性設定含檢測 Rank A+

SSL 相關安全測試含修正 SSL 申請可以透過 SSL For Free 進行申請免費 SSL https://www.sslforfree.com/ 檢測 SSL 憑證安全的十種工具 https://geekflare.com/ssl-test-certificate/#SSL-Labs 如果有使用 VirtualHost 記得加在設定裡就可以 $ vim /etc/httpd/conf/http.conf   <VirtualHost *:80> RewriteEngine on RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK) RewriteRule .* - [F] Alias /cp /var/www/cp/public <Directory /var/www/cp> AllowOverride All </Directory> <Directory /var/www/html> AllowOverride All </Directory> DocumentRoot /var/www/html ServerName www.sakura-home.com.tw </VirtualHost> <VirtualHost *:443> Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;" RewriteEngine on RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK) RewriteRule .* - [F] SSLEngine on SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 ...