我很懶 能坐著就不會站著,能躺著就不會坐著
能用 Nginx 就用 Nginx,不過這只是因為我比較常用
很久以前小的時候曾經不知道幹嘛弄過 apache
突然某天心血來潮,想說複習一下 apache 要怎麼架起來
這樣找工作的 resume 又可以多一項可以說嘴的(?
然後我就在 ubuntu 弄了 apache 來部署新專案
通常我在伺服器裡面都用 docker 去跑專案
再用 HTTP 伺服器 proxy docker run 的 port 讓外部可以請求
apache 設定檔如下
簡單說明一下
當請求是 http 時強制導向 443 變成 https
443 那邊也有 SSL 的配置設定
如果需要取用的話,記得請把 your.domain
& /your/path
改成自己的 domain 和 SSL 憑證路徑
<VirtualHost *:80>
ServerName your.domain
#ReDirect any HTTP request to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
RequestHeader set x-Forwarded-Host "your.domain"
</Virtualhost>
<VirtualHost *:443>
ServerName your.domain
# SSL Certification
SSLEngine On
SSLCertificateFile /your/path
SSLCertificateKeyFile /your/path
SSLCertificateChainFile /your/path
# HSTS
Header always set Strict-Transport-Security "max-age=63072000;includeSubdomains;"
# Remove this if site need to use frames or iframes
Header always set X-Frame-Options DENY
# Prvent MIME bsed attacks
Header set X-Content-Type-Options "nosniff"
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
</IfModule>
ProxyRequests Off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
</VirtualHost>
我的主機用 ubuntu 所以我就塞進 /etc/apache2/sites-enabled
這個 folder 裡面
會塞那邊的原因是因為我看 /etc/apache2/apache2.conf
的設定檔有 import IncludeOptional sites-enabled/*.conf
sites-enabled
資料夾裡面所有的 conf 檔,所以就不客氣丟進去了
沒想到一直報錯,都跟 proxy 有關
AH01144: No protocol handler was valid for the URL / (scheme 'http'). If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
看 log 一直出現這個錯誤
查了一下才發現 要啟用 Proxy Modules
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
浪費了我快20分鐘 嗚嗚
參考