差異處
這裏顯示兩個版本的差異處。
| 兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
| tech:apache [2011/02/20 22:12] – [參考資料] jonathan | tech:apache [2025/10/17 10:59] (目前版本) – [- ProxyPass directive 抓遠端主機頁面] jonathan | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== Apache WebServer 設定技巧 ====== | ||
| + | ===== 設定啟用 HSTS ===== | ||
| + | * [[https:// | ||
| + | * 將 httpd.conf 內的 headers_module 啟用< | ||
| + | : | ||
| + | LoadModule headers_module modules/ | ||
| + | :</ | ||
| + | * VirtualHost 內增加 header 設定< | ||
| + | : | ||
| + | < | ||
| + | Header always set Strict-Transport-Security " | ||
| + | </ | ||
| + | < | ||
| + | Header always set Strict-Transport-Security " | ||
| + | </ | ||
| + | : | ||
| + | </ | ||
| + | |||
| + | **如果是 Debian 環境** | ||
| + | * < | ||
| + | * 編輯 virtual host exp. < | ||
| + | : | ||
| + | < | ||
| + | UseCanonicalName Off | ||
| + | ServerAdmin | ||
| + | DocumentRoot / | ||
| + | Header always set Strict-Transport-Security " | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | SSLEngine on | ||
| + | ServerAdmin | ||
| + | DocumentRoot / | ||
| + | Header always set Strict-Transport-Security " | ||
| + | </ | ||
| + | : | ||
| + | </ | ||
| + | * 重新啟動 apache < | ||
| + | |||
| + | |||
| + | ===== 改用 MPM worker 模組提升效能 ===== | ||
| + | * https:// | ||
| + | |||
| + | ===== 設定多個不同網域(Domain Name)網站設定 ===== | ||
| + | * 假設要設定 | ||
| + | * www.abc.com 目錄是 / | ||
| + | * www.xyz.com 目錄是 / | ||
| + | * 主要是修改 / | ||
| + | : | ||
| + | : | ||
| + | ### Section 3: Virtual Hosts | ||
| + | : | ||
| + | NameVirtualHost *:80 | ||
| + | : | ||
| + | < | ||
| + | ServerName www.abc.com | ||
| + | ServerAdmin [email protected] | ||
| + | DocumentRoot / | ||
| + | CustomLog logs/ | ||
| + | ErrorLog logs/ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | ServerName www.xyz.com | ||
| + | ServerAdmin [email protected] | ||
| + | DocumentRoot / | ||
| + | CustomLog logs/ | ||
| + | ErrorLog logs/ | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | ===== 開啟與關閉顯示目錄檔案清單 ===== | ||
| + | 通常基於資訊安全因素會關閉顯示目錄檔案清單, | ||
| + | < | ||
| + | : | ||
| + | # Note that " | ||
| + | : | ||
| + | # | ||
| + | |||
| + | # | ||
| + | # 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/ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== - ProxyPass directive 抓遠端主機頁面 ===== | ||
| + | 我是用在將 VMWare 在內部運作的網頁能夠簡易的呈現到 Internet 的 WebServer 上. | ||
| + | |||
| + | < | ||
| + | graph LR | ||
| + | Browser[" | ||
| + | WebServer[" | ||
| + | VMmail[" | ||
| + | | ||
| + | Browser --> | ||
| + | WebServer --> | ||
| + | | ||
| + | style Browser fill:# | ||
| + | style WebServer fill:# | ||
| + | style VMmail fill:# | ||
| + | </ | ||
| + | |||
| + | Browser 連上 webServer(http:// | ||
| + | |||
| + | ==== WebServer 設定方式 ==== | ||
| + | * apache 要有安裝 mod_proxy (預設已經安裝) | ||
| + | * 只要在 httpd.conf 內定義 : | ||
| + | < | ||
| + | ProxyPass /webmail http:// | ||
| + | </ | ||
| + | 這樣 http:// | ||
| + | |||
| + | ==== vm-mail 設定方式 ==== | ||
| + | 只要依據一般正常的 web server 設定即可 | ||
| + | |||
| + | ===== 自訂找不到網頁的設定方式 ===== | ||
| + | 當某個網站移轉到新的網址, | ||
| + | |||
| + | < | ||
| + | : | ||
| + | < | ||
| + | ServerName sport.ichiayi.com | ||
| + | ServerAdmin [email protected] | ||
| + | DocumentRoot / | ||
| + | ErrorDocument 404 /err404.htm | ||
| + | : | ||
| + | |||
| + | </ | ||
| + | |||
| + | 然後編輯 / | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | |||
| + | <meta http-equiv=" | ||
| + | <meta http-equiv=" | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | < | ||
| + | <a href=http:// | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== 設定特定IP存取目錄不需要輸入帳號密碼 ===== | ||
| + | 針對特定 IP 來存取目錄時, | ||
| + | * 只要來自 192.168.11.* 都不需要輸入帳號密碼, | ||
| + | * 其他的 IP 都需要輸入帳號密碼, | ||
| + | < | ||
| + | |||
| + | < | ||
| + | Order deny,allow | ||
| + | Deny from all | ||
| + | AuthType Basic | ||
| + | AuthName " | ||
| + | AuthUserFile / | ||
| + | Require valid-user | ||
| + | Allow from 192.168.11. | ||
| + | Satisfy Any | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | ===== 參考資料 ===== | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | {{tag> | ||