====== Apache WebServer 設定技巧 ====== ===== 設定啟用 HSTS ===== * [[https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security|點這裡了解 HSTS(HTTP Strict Transport Security)]] * 將 httpd.conf 內的 headers_module 啟用 : LoadModule headers_module modules/mod_headers.so : * VirtualHost 內增加 header 設定 : Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" : **如果是 Debian 環境** * sudo a2enmod headers * 編輯 virtual host exp. vi sites-enabled/wordpress.conf : UseCanonicalName Off ServerAdmin webmaster@localhost DocumentRoot /var/www/wordpress Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains" SSLEngine on ServerAdmin webmaster@localhost DocumentRoot /var/www/wordpress Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains" : * 重新啟動 apache sudo systemctl restart apache2 ===== 改用 MPM worker 模組提升效能 ===== * https://www.brilliantcode.net/877/apache-2-2-2-4-performance-tuning-mpm-engine/ ===== 設定多個不同網域(Domain Name)網站設定 ===== * 假設要設定 * www.abc.com 目錄是 /var/www/www.abc.com/ * www.xyz.com 目錄是 /var/www/www.xyz.com/ * 主要是修改 /etc/httpd/conf/httpd.conf : : ### Section 3: Virtual Hosts : NameVirtualHost *:80 : ServerName www.abc.com ServerAdmin admin@abc.com DocumentRoot /var/www/www.abc.com CustomLog logs/www.abc.com-access_log common ErrorLog logs/www.abc.com-error_log ServerName www.xyz.com ServerAdmin admin@xyz.com DocumentRoot /var/www/www.xyz.com CustomLog logs/www.xyz.com-access_log common ErrorLog logs/www.xyz.com-error_log ===== 開啟與關閉顯示目錄檔案清單 ===== 通常基於資訊安全因素會關閉顯示目錄檔案清單, 所以在 httpd.conf 內會設定所有目錄都不顯示 (也就是移除掉 **MultiViews** 的設定), 將 Options Indexes FollowSymLinks 前面加上 # : # Note that "MultiViews" must be named *explicitly* --- "Options All" : # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. 如果要顯示目錄檔案清單,可以針對特定目錄設定 Options 有 MultiViews 功能, Exp. /Stuff 以下可以針對特定 IP 來源存取並出現檔案目錄清單 Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Order deny,allow Deny from all Allow from 127.0.0.1 Allow from 192.168.11.0/24 ===== - ProxyPass directive 抓遠端主機頁面 ===== 我是用在將 VMWare 在內部運作的網頁能夠簡易的呈現到 Internet 的 WebServer 上. +----------------------+ +--------------+ +---------+ | webServer(ProxyPass) | | vm-mail | | Browser +-->+ /webmail +-->+ /webmail | +---------+ | mail.ichiayi.com | |192.168.11.238| +----------------------+ +--------------+ Browser 連上 webServer(http://mail.ichiayi.com/webmail), 出現的畫面是由 vm-mail(http://192.168.11.238/webmail) 所提供頁面 ==== WebServer 設定方式 ==== * apache 要有安裝 mod_proxy (預設已經安裝) * 只要在 httpd.conf 內定義 : ProxyPass /webmail http://192.168.11.238/webmail 這樣 http://mail.ichiayi.com/webmail/ 就可以正確轉讀至 http://192.168.11.238/webmail 網頁功能 ==== vm-mail 設定方式 ==== 只要依據一般正常的 web server 設定即可 ===== 自訂找不到網頁的設定方式 ===== 當某個網站移轉到新的網址, 原本網頁在舊網址內都移除掉, 希望只要在 Google 找到舊的網址都能出現已經移到新的網址的訊息.. 這時就可以將 404 找不到網頁的訊息, 自訂成說明網址移轉的網頁. 設定方式只要在 httpd.conf 內增加一行, 指定呈現的轉只說明頁面. : ServerName sport.ichiayi.com ServerAdmin lintsai@ichiayi.com DocumentRoot /backup/lintsai/sport ErrorDocument 404 /err404.htm : 然後編輯 /backup/lintsai/sport/err404.htm 嘉義市體育會~已經更新網址~
按這邊直接連結到新網址
===== 設定特定IP存取目錄不需要輸入帳號密碼 ===== 針對特定 IP 來存取目錄時, 可以免除輸入帳號密碼增加方便性的設定方式如下: * 只要來自 192.168.11.* 都不需要輸入帳號密碼, 就可直接存取 mydata * 其他的 IP 都需要輸入帳號密碼, 才可存取 mydata Order deny,allow Deny from all AuthType Basic AuthName "Authorization Realm" AuthUserFile /data/web-data/mydata.user Require valid-user Allow from 192.168.11. Satisfy Any ===== 參考資料 ===== * http://httpd.apache.org/docs/1.3/mod/mod_proxy.html#proxypass * http://httpd.apache.org/docs/2.0/custom-error.html * http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html#allow-conditional * http://httpd.apache.org/docs/2.2/mod/core.html#satisfy * https://docs.microfocus.com/SM/9.60/Hybrid/Content/security/concepts/support_of_http_strict_transport_security_protocol.htm * https://www.simplified.guide/apache/enable-hsts {{tag>apache httpd 密技}}