Category: apache

[apache] apache 2.4.17 支援 http/2,開啟 http/2 增進我的網頁載入速度

最新的 apache 2.4.17 支援了 http/2 http/2 的詳細內容 簡單來說,支援了壓縮的 http header、平行下載與多工發送伺服器請求、資源優先下載控制與向下支援 http/1.1。 網路上有非常多 http/2 與  http/1.1 的比較測試。 如:http2與 http1.1 差別測試 這邊先看一下目前瀏覽器支援 http/2 的狀況,目前主流瀏覽器都只支援 https 才能使用 http/2。(紫色框框) 首先要先將 apache 更新至 2.4.17,或安裝最新版。(由於各版本更新方法各有不同,這邊就不詳述) 設定 https 加密連線 (如:安裝letsencrypt) 開啟 mod_http2 模組 sudo a2enmod http2 測試網站是否成功支援 http/2 https://tools.keycdn.com/http2-test 參考資料: https://simular.co/knowledge/site-build/68-about-http2-and-http11.html

[apache] 同時使用 apache 與 nodejs,反向代理 nodejs

這幾天有一些服務後端用到 nodejs,但主要的網頁服務還是 apache 來處理,因此想說是否可以同時運行 nodejs 與 apache。   其實如果可以的話,使用 nginx 來做代理伺服器會更好(比 apache 處理的效能好,比較不會這麼限制 nodejs 速度) 由於我機器上面已經裝有LAMP的環境,並且運行部分服務,因此先使用 apache 來做代理伺服器堪用一下。 開啟 mod_proxy 及 mod_proxy_http sudo a2enmod proxy sudo a2enmod proxy_http 重新啟動 apache sudo service apache2 restart 編輯 /etc/apache2/sites-enabled/000-default.conf,nodejs 預設 port 為 3000 <VirtualHost *:80> # reverse proxy <Proxy *> Order deny,allow Allow from all </Proxy> <Location /> […]

[apache] apache 設定 HSTS ( HTTP Strict Transport Security )

之前曾經介紹過如何透過 apache 的.htaccess 強制使用 https 連線,但實際上此作法瀏覽器還是可能與機器建立 http 連線之後,再改而建立 https 連線。 如果可以的話,我們會希望一開始就嘗試建立 https 連線。   HSTS( HTTP Strict Transport Security ) https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security 簡單說明一下,原則上就是我們在網頁伺服器端( 如: apache、nginx 等)設置 response 的 header,瀏覽器若支援HSTS則會根據 header 作日後相對應的行為。 如:Strict-Transport-Security: max-age=31536000; includeSubDomains 支援 HSTS 的瀏覽器,會在日後一年對此網域的網站嘗試直接建立 https 連線。 支援度: 各主流瀏覽器大多皆有支援 好處: 有很多攻擊 https 網站的手法( sslstrip 等),都是透過剝離 https 連線,轉而取代使用 http 連線,進而達到資料竊取或攻擊的行為,使用 HSTS 可以有效避免此類攻擊。 apache設定: 開啟 apache […]

[apache] 強制網站及 wordpress 使用 https 私人連線

安裝完了 letscrypt 後,當然要讓自己的網站都強制使用 https 較安全的連線囉! 首先要先開啟 rewrite module sudo a2enmod rewrite 打開 /etc/apache2/apache2.conf ,加入以下程式碼 <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] </Directory> 若為 wordpress ,則要進入wordpress 目錄後複寫 .htaccess # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f […]

[ubuntu] apache 安裝 Let’s Encrypt ,讓你的網站更安全

安裝 Let’s Encrypt 可以讓我們的網頁加上 TLS/SSL 的加密,也就是 https 的協定,除了安全性之外,也能提高網頁的 SEO 排名。 ubuntu 14.04 上面沒有包好的 package,因此安裝會複雜些 記得要確認自己 apache 設定(/etc/apache2/sites-available/000-default.conf)中的 ServerName 要設定,以免後續抓不到 ServerName ServerName domain.com 更新套件清單 sudo apt-get update 安裝git sudo apt-get install git 將 github 上的 lets encrypt 專案 clone 下來 sudo git clone https://github.com/letsencrypt/letsencrypt 進入專案資料夾 cd /letscrypt 開啟 apache ssl module sudo a2enmod ssl sudo service […]

[apache] virtual host 虛擬網站/虛擬主機

最近買了 domain,比如 xxxx.com 但我們可能想設個人網站為 personal.xxxx.com,部落格網站為 blog.xxxx.com 然而這兩個網站都對應到同一台主機,這時候我們就需要 virtual host的 功能了。   複製/etc/apache2/sites-available/000-default.conf <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear […]

[ubuntu] apache ServerName 警告訊息

過去在 ubuntu 安裝完 apache,啟動時總是會出現以下這段訊息 apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message 最近才試著去解決產生此訊息的問題 其實是 apache2 抓不到 hostname,因此我們正確的設定 hostname 就正常了 sudo hostname ubuntu.mydomain.com 參考文章:http://blog.miniasp.com/post/2012/06/23/apache2-Could-not-reliably-determine-the-server-fully-qualified-domain-name-using-for-ServerName.aspx  

[ubuntu 14.04] apache 目錄開啟.htaccess 覆寫

啟用apache 的 mod_rewrite 模組 sudo a2enmod rewrite 重新啟動apache,重新讀取模組,設定才會生效 sudo service apache2 restart 更改目錄設定檔為允許覆寫,如(/etc/apache2/apache2.conf) <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 重新啟動apache,重新讀取設定檔,設定才會生效 sudo service apache2 restart  完成,可以在目錄下創建.htaccess檔案,覆寫設定