歡迎光臨
每天分享高質量文章

如何在 Ubuntu 上安裝和最佳化 Apache | Linux 中國

Apache (又名 httpd) 是最受歡迎和使用最廣泛的 web 伺服器,所以這應該對每個人都有用。
— Thishosting


致謝
編譯自 | https://thishosting.rocks/how-to-install-optimize-apache-ubuntu/ 
 作者 | Thishosting
 譯者 | MjSeven ? ? ? ? 共計翻譯:40 篇 貢獻時間:114 天

這是我們的 LAMP 系列教程的開始:如何在 Ubuntu 上安裝 Apache web 伺服器。

這些說明適用於任何基於 Ubuntu 的發行版,包括 Ubuntu 14.04、 Ubuntu 16.04、 Ubuntu 18.04[1],甚至非 LTS 的 Ubuntu 發行版,例如 Ubuntu 17.10。這些說明經過測試併為 Ubuntu 16.04 編寫。

Apache (又名 httpd) 是最受歡迎和使用最廣泛的 web 伺服器,所以這應該對每個人都有用。

開始安裝 Apache 之前

在我們開始之前,這裡有一些要求和說明:

◈ Apache 可能已經在你的伺服器上安裝了,所以開始之前首先檢查一下。你可以使用 apachectl -V 命令來顯示你正在使用的 Apache 的版本和一些其他資訊。
◈ 你需要一個 Ubuntu 伺服器。你可以從 Vultr[2] 購買一個,它們是最便宜的雲託管服務商[3]之一。它們的伺服器價格每月 2.5 美元起。(LCTT 譯註:廣告 ≤_≤ )
◈ 你需要有 root 使用者或具有 sudo 訪問許可權的使用者。下麵的所有命令都由 root 使用者執行,所以我們不必為每個命令都新增 sudo
◈ 如果你使用 Ubuntu,則需要啟用 SSH[4],如果你使用 Windows,則應該使用類似 MobaXterm[5] 的 SSH 客戶端。

這就是全部要求和註釋了,讓我們進入安裝過程。

在 Ubuntu 上安裝 Apache

你需要做的第一件事就是更新 Ubuntu,這是在你做任何事情之前都應該做的。你可以執行:

  1. apt-get update && apt-get upgrade

接下來,安裝 Apache,執行以下命令:

  1. apt-get install apache2

如果你願意,你也可以安裝 Apache 檔案和一些 Apache 實用程式。對於我們稍後將要安裝的一些模組,你將需要一些 Apache 實用程式。

  1. apt-get install apache2-doc apache2-utils

*就是這樣。你已經成功安裝了 Apache *

你仍然需要配置它。

在 Ubuntu 上配置和最佳化 Apache

你可以在 Apache 上做各種各樣的配置,但是主要的和最常見的配置將在下麵做出解釋。

檢查 Apache 是否正在執行

預設情況下,Apache 設定為在機器啟動時自動啟動,因此你不必手動啟用它。你可以使用以下命令檢查它是否正在執行以及其他相關資訊:

  1. systemctl status apache2

check if apache is running

並且你可以檢查你正在使用的版本:

  1. apachectl -V

一種更簡單的檢查方法時訪問伺服器的 IP 地址,如果你得到預設的 Apache 頁面,那麼一切都正常。

更新你的防火牆

如果你使用防火牆(你應該使用它),則可能需要更新防火牆規則並允許訪問預設埠。Ubuntu 上最常用的防火牆是 UFW,因此以下說明使用於 UFW。

要允許透過 80(http)和 443(https)埠的流量,執行以下命令:

  1. ufw allow 'Apache Full'

安裝常見的 Apache 模組

一些模組經常被建議使用,所以你應該安裝它們。我們將包含最常見模組的說明:

使用 PageSpeed 加速你的網站

PageSpeed 模組將自動最佳化並加速你的 Apache 伺服器。

首先,進入 PageSpeed 下載頁[6]並選擇你需要的的檔案。我們使用的是 64 位 Ubuntu 伺服器,所以我們安裝最新的穩定版本。使用 wget 下載它:

  1. wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb

然後,使用以下命令安裝它:

  1. dpkg -i mod-pagespeed-stable_current_amd64.deb

  2. apt-get -f install

重啟 Apache 以使更改生效:

  1. systemctl restart apache2

使用 mod_rewrite 模組啟動重寫/重定向

顧名思義,該模組用於重寫(重定向)。如果你使用 WordPress 或任何其他 CMS 來處理此問題,你就需要它。要安裝它,只需執行:

  1. a2enmod rewrite

然後再次重新啟動 Apache。你可能需要一些額外的配置,具體取決於你使用的 CMS,如果有的話。為你的設定 Google 一下得到它的具體說明。

使用 ModSecurity 模組保護你的 Apache

顧名思義,ModSecurity 是一個用於安全性的模組,它基本上起著防火牆的作用,它可以監控你的流量。要安裝它,執行以下命令:

  1. apt-get install libapache2-modsecurity

再次重啟 Apache:

  1. systemctl restart apache2

ModSecurity 自帶了一個預設的設定,但如果你想擴充套件它,你可以使用 OWASP 規則集[7]

使用 mod_evasive 模組抵禦 DDoS 攻擊

儘管 mod_evasive 在防止攻擊方面有多大用處值得商榷,但是你可以使用它來阻止和防止伺服器上的 DDoS 攻擊。要安裝它,使用以下命令:

  1. apt-get install libapache2-mod-evasive

預設情況下,mod_evasive 是禁用的,要啟用它,編輯以下檔案:

  1. nano /etc/apache2/mods-enabled/evasive.conf

取消註釋所有行(即刪除 #),根據你的要求進行配置。如果你不知道要編輯什麼,你可以保持原樣。

mod_evasive

建立一個日誌檔案:

  1. mkdir /var/log/mod_evasive

  2. chown -R www-data:www-data /var/log/mod_evasive

就是這樣。現在重啟 Apache 以使更改生效。

  1. systemctl restart apache2

你可以安裝和配置附加模組[8],但完全取決於你和你使用的軟體。它們通常不是必需的。甚至我們上麵包含的 4 個模組也不是必需的。如果特定應用需要模組,那麼它們可能會註意到這一點。

用 Apache2Buddy 指令碼最佳化 Apache

Apache2Buddy 是一個可以自動調整 Apache 配置的指令碼。你唯一需要做的就是執行下麵的命令,指令碼會自動完成剩下的工作:

  1. curl -sL https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl | perl

如果你沒有安裝 curl,那麼你可能需要安裝它。使用以下命令來安裝 curl

  1. apt-get install curl

額外配置

用 Apache 還可以做一些額外的東西,但我們會留下它們作為另一個教程。像啟用 http/2 支援,關閉(或開啟) KeepAlive,調整你的 Apache 甚至更多。這些東西你現在不需要做,但是如果你在網上找到了教程,並且如果你等不及我們的教程,那就去做吧。

使用 Apache 建立你的第一個網站

現在我們已經完成了所有的調優工作,讓我們開始建立一個實際的網站。按照我們的指示建立一個簡單的 HTML 頁面和一個在 Apache 上執行的虛擬主機。

你需要做的第一件事是為你的網站建立一個新的目錄。執行以下命令來執行此操作:

  1. mkdir -p /var/www/example.com/public_html

當然,將 example.com 替換為你所需的域名。你可以從 Namecheap[9] 獲得一個便宜的域名。

不要忘記在下麵的所有命令中替換 example.com

接下來,建立一個簡單的靜態網頁。建立 HTML 檔案:

  1. nano /var/www/example.com/public_html/index.html

貼上這些:

  1.     

  2.        </span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">Simple Page</span><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"/></code></p></li></ol></pre> </section> <li> <p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"/></code></p> </li> <li> <p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"/></code></p> </li> <li> <p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"></p> <p/></span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">If you're seeing this in your browser then everything works.</span><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"/></code></p> </li> <li> <p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"/></code></p> </li> <li> <p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"/></code></p> </li> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">儲存並關閉檔案。</p> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">配置目錄的許可權:</p> <pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word;background-color: rgb(22, 27, 32);background-image: none;box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px;text-shadow: rgb(0, 0, 0) 0px 1px 1px;border-radius: 6px;color: rgb(184, 255, 184);margin: 10px;padding: 1em 1em 1em 0px;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(0, 0, 0);line-height: 1.2em;letter-spacing: 0px !important;"><ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;"><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="kwd" style="word-wrap: break-word;color: rgb(226, 137, 100);">chown</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">R www</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">data</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">www</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">data </span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="kwd" style="word-wrap: break-word;color: rgb(226, 137, 100);">var</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">www</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">example</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">.</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">com</span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="kwd" style="word-wrap: break-word;color: rgb(226, 137, 100);">chmod</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">R og</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">r </span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="kwd" style="word-wrap: break-word;color: rgb(226, 137, 100);">var</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">www</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">example</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">.</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">com</span></code></p></li></ol></pre> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">為你的網站建立一個新的虛擬主機:</p> <pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word;background-color: rgb(22, 27, 32);background-image: none;box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px;text-shadow: rgb(0, 0, 0) 0px 1px 1px;border-radius: 6px;color: rgb(184, 255, 184);margin: 10px;padding: 1em 1em 1em 0px;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(0, 0, 0);line-height: 1.2em;letter-spacing: 0px !important;"><ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;"><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="kwd" style="word-wrap: break-word;color: rgb(226, 137, 100);">nano</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">etc</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">apache2</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">sites</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">available</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">example</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">.</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">com</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">.</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">conf</span></code></p></li></ol></pre> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">貼上以下內容:</p> <pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word;background-color: rgb(22, 27, 32);background-image: none;box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px;text-shadow: rgb(0, 0, 0) 0px 1px 1px;border-radius: 6px;color: rgb(184, 255, 184);margin: 10px;padding: 1em 1em 1em 0px;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(0, 0, 0);line-height: 1.2em;letter-spacing: 0px !important;"><ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;"><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"><virtualhost><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);"> *:80</span><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);">></span></virtualhost></span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     ServerAdmin admin@example.com</span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     ServerName example.com</span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     ServerAlias www.example.com</span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">   </span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     DocumentRoot /var/www/example.com/public_html</span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">    </span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     ErrorLog ${APACHE_LOG_DIR}/error.log</span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">     CustomLog ${APACHE_LOG_DIR}/access.log combined</span></code></p></li><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="tag" style="word-wrap: break-word;color: rgb(137, 189, 255);"/></code></p></li></ol></pre> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">這是一個基礎的虛擬主機。根據你的設定,你可能需要更高階的 <code style="word-wrap: break-word;background: none rgb(238, 238, 238);padding: 2px 4px;border-radius: 4px;margin-right: 4px;margin-left: 4px;color: rgb(33, 150, 243);line-height: 1.2em;">.conf</code> 檔案。</p> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">在更新所有內容後儲存並關閉檔案。</p> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">現在,使用以下命令啟用虛擬主機:</p> <pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word;background-color: rgb(22, 27, 32);background-image: none;box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px;text-shadow: rgb(0, 0, 0) 0px 1px 1px;border-radius: 6px;color: rgb(184, 255, 184);margin: 10px;padding: 1em 1em 1em 0px;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(0, 0, 0);line-height: 1.2em;letter-spacing: 0px !important;"><ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;"><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">a2ensite example</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">.</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">com</span><span class="pun" style="word-wrap: break-word;color: rgb(184, 255, 184);">.</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);">conf</span></code></p></li></ol></pre> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">最後,重啟 Apache 以使更改生效:</p> <pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word;background-color: rgb(22, 27, 32);background-image: none;box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px;text-shadow: rgb(0, 0, 0) 0px 1px 1px;border-radius: 6px;color: rgb(184, 255, 184);margin: 10px;padding: 1em 1em 1em 0px;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(0, 0, 0);line-height: 1.2em;letter-spacing: 0px !important;"><ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;"><li><p><code style="word-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="kwd" style="word-wrap: break-word;color: rgb(226, 137, 100);">systemctl</span><span class="pln" style="word-wrap: break-word;color: rgb(184, 255, 184);"> restart apache2</span></code></p></li></ol></pre> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">這就是全部了,你做完了。現在你可以訪問 example.com 並檢視你的頁面。</p> <hr style="word-wrap: break-word;clear: both;margin-right: 10px;margin-left: 10px;"/> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">via: <span style="word-wrap: break-word;color: rgb(77, 138, 216);">https://thishosting.rocks/how-to-install-optimize-apache-ubuntu/</span></p> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">作者:<span style="word-wrap: break-word;color: rgb(77, 138, 216);">ThisHosting</span><span class="sup" style="word-wrap: break-word;font-size: 9px;vertical-align: super;background-color: rgb(102, 102, 102);color: rgb(255, 255, 255);transform: scale(0.75);display: inline-block;padding: 1px;line-height: 1em;">[11]</span> 譯者:<span style="word-wrap: break-word;color: rgb(77, 138, 216);">MjSeven</span> 校對:<span style="word-wrap: break-word;color: rgb(77, 138, 216);">wxy</span></p> <p style="word-wrap: break-word;margin-top: 1.5em;margin-bottom: 1.5em;line-height: 2em;">本文由 <span style="word-wrap: break-word;color: rgb(77, 138, 216);">LCTT</span> 原創編譯,<span style="word-wrap: break-word;color: rgb(77, 138, 216);">Linux中國</span> 榮譽推出</p> <p></p> <div class="ct_mpda_wrp" id="js_sponsor_ad_area" style="display:none;"/> <div class="reward_area tc reward_area_primary" id="js_preview_reward_author" style="display:none;"> <div class="reward-avatar" id="js_preview_reward_author_avatar" style="display: none;"> <img alt="" id="js_preview_reward_author_head" src=""/> </div> <div class="reward-author" id="js_preview_reward_author_name">譯者:MjSeven</div> <p class="reward_tips js_preview_reward_author_wording" style="display:none;"/> <p> <a class="reward_access" csmlink="Fstv3c" href="http://chuansongme.com/r/Fstv3c" id="js_preview_reward_author_link" rel="nofollow"><span id="js_preview_reward_link_text">贊賞</span></a> </p> </div> <div class="reward_qrcode_area reward_area tc" id="js_preview_reward_qrcode" style="display:none;"> <p class="tips_global">長按二維碼向我轉賬</p> <p class="reward_tips" id="js_preview_reward_ios_wording" style="display:none;"/> <span class="reward_qrcode_img_wrp"><img class="reward_qrcode_img" src="//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/pic/appmsg/pic_reward_qrcode.2x3534dd.png"/></span></p> <p class="tips_global">受蘋果公司新規定影響,微信 iOS 版的贊賞功能被關閉,可透過二維碼轉賬支援公眾號。</p> </div> <ul class="article_extend_area" id="js_hotspot_area"/> <div class="rich_media_tool" id="js_toobar3"> <a class="media_tool_meta meta_primary" csmlink="Ostv3c" href="http://chuansongme.com/r/Ostv3c" id="js_view_source" rel="nofollow" target="_blank">閱讀原文</a></p> </div> <div id="js_minipro_dialog" style="display:none;"> <div class="weui-mask"/> <div class="weui-dialog"> <div class="weui-dialog__bd">即將開啟”<span id="js_minipro_dialog_name"/>“小程式</div> <div class="weui-dialog__ft"> <a class="weui-dialog__btn weui-dialog__btn_default" href="javascript:void(0);" id="js_minipro_dialog_cancel">取消</a><br /> <a class="weui-dialog__btn weui-dialog__btn_primary" href="javascript:void(0);" id="js_minipro_dialog_ok">開啟</a> </div> </div> </div> </div> </article> <div class="post-actions"> <a href="javascript:;" class="post-like action action-like" data-pid="7572"><i class="fa fa-thumbs-o-up"></i>贊(<span>0</span>)</a> </div> <div class="action-share"></div> <div class="article-tags">標籤:<a href="https://www.ipshop.xyz/tag/apache" rel="tag">Apache</a><a href="https://www.ipshop.xyz/tag/google" rel="tag">Google</a><a href="https://www.ipshop.xyz/tag/ios" rel="tag">iOS</a><a href="https://www.ipshop.xyz/tag/linux" rel="tag">Linux</a><a href="https://www.ipshop.xyz/tag/%e5%84%aa%e5%8c%96" rel="tag">最佳化</a><a href="https://www.ipshop.xyz/tag/%e5%ae%89%e5%85%a8" rel="tag">安全</a></div> <nav class="article-nav"> <span class="article-nav-prev">上一篇<br><a href="https://www.ipshop.xyz/7571.html" rel="prev">在 CentOS 6 系統上安裝最新版 Python3 軟體包的 3 種方法 | Linux 中國</a></span> <span class="article-nav-next">下一篇<br><a href="https://www.ipshop.xyz/7573.html" rel="next">【每日安全資訊】在GDPR生效第一天Facebook和谷歌就面臨88億美元的訴訟打擊</a></span> </nav> <div class="relates"><div class="title"><h3>相關推薦</h3></div><ul><li><a href="https://www.ipshop.xyz/18292.html">分庫分表實戰:可能是使用者表最佳分庫分表方案</a></li><li><a href="https://www.ipshop.xyz/18291.html">4 張 GIF 圖幫助你理解二叉搜尋樹</a></li><li><a href="https://www.ipshop.xyz/17827.html">分散式鏈路追蹤 SkyWalking 原始碼分析 —— Agent 收集 Trace 資料</a></li><li><a href="https://www.ipshop.xyz/17784.html">一份來自英偉達的越南小姐姐整理的機器學習入門清單,照這樣學就對了</a></li><li><a href="https://www.ipshop.xyz/17854.html">HBase 資料遷移方案介紹</a></li><li><a href="https://www.ipshop.xyz/17853.html">C# 管道式程式設計</a></li><li><a href="https://www.ipshop.xyz/17787.html">不會SQL註入,連漫畫都看不懂了</a></li><li><a href="https://www.ipshop.xyz/17782.html">向Excel說再見,神級編輯器統一表格與Python</a></li></ul></div> </div> </div> <div class="sidebar"> <div class="widget widget_ui_asb"><div class="item"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- ad3 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3715363832600463" data-ad-slot="8216000168" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script></div></div><div class="widget widget_ui_tags"><h3>熱門標籤</h3><div class="items"><a href="https://www.ipshop.xyz/tag/ios">iOS (11238)</a><a href="https://www.ipshop.xyz/tag/%e5%be%ae%e8%bb%9f">微軟 (4955)</a><a href="https://www.ipshop.xyz/tag/linux">Linux (4274)</a><a href="https://www.ipshop.xyz/tag/%e5%ae%89%e5%85%a8">安全 (4180)</a><a href="https://www.ipshop.xyz/tag/python">Python (4161)</a><a href="https://www.ipshop.xyz/tag/%e6%80%a7%e8%83%bd">效能 (3165)</a><a href="https://www.ipshop.xyz/tag/%e9%81%8b%e7%b6%ad">運維 (2774)</a><a href="https://www.ipshop.xyz/tag/%e5%84%aa%e5%8c%96">最佳化 (2419)</a><a href="https://www.ipshop.xyz/tag/net">.NET (2262)</a><a href="https://www.ipshop.xyz/tag/google">Google (2136)</a><a href="https://www.ipshop.xyz/tag/%e6%a9%9f%e5%99%a8%e5%ad%b8%e7%bf%92">機器學習 (1795)</a><a href="https://www.ipshop.xyz/tag/%e4%bd%b5%e7%99%bc">併發 (1613)</a><a href="https://www.ipshop.xyz/tag/%e5%88%86%e4%bd%88%e5%bc%8f">分散式 (1559)</a><a href="https://www.ipshop.xyz/tag/%e9%9b%86%e7%be%a4">叢集 (1240)</a><a href="https://www.ipshop.xyz/tag/sql">SQL (1174)</a><a href="https://www.ipshop.xyz/tag/mysql">Mysql (1060)</a><a href="https://www.ipshop.xyz/tag/%e5%8d%80%e5%a1%8a%e9%8f%88">區塊鏈 (1017)</a><a href="https://www.ipshop.xyz/tag/docker">Docker (977)</a><a href="https://www.ipshop.xyz/tag/%e5%be%ae%e6%9c%8d%e5%8b%99">微服務 (922)</a><a href="https://www.ipshop.xyz/tag/%e9%9d%a2%e8%a9%a6">面試 (919)</a><a href="https://www.ipshop.xyz/tag/apache">Apache (743)</a><a href="https://www.ipshop.xyz/tag/nlp">NLP (725)</a><a href="https://www.ipshop.xyz/tag/redis">Redis (719)</a><a href="https://www.ipshop.xyz/tag/android">Android (668)</a><a href="https://www.ipshop.xyz/tag/git">Git (640)</a><a href="https://www.ipshop.xyz/tag/%e6%9e%b6%e6%a7%8b%e5%b8%ab">架構師 (632)</a><a href="https://www.ipshop.xyz/tag/nginx">Nginx (630)</a><a href="https://www.ipshop.xyz/tag/facebook">Facebook (599)</a><a href="https://www.ipshop.xyz/tag/jvm">JVM (595)</a><a href="https://www.ipshop.xyz/tag/%e7%88%ac%e8%9f%b2">爬蟲 (476)</a></div></div><div class="widget widget_ui_posts"><h3>熱門文章</h3><ul class="nopic"><li><a href="https://www.ipshop.xyz/15779.html"><span class="text">用 docker-compose 啟動 WebApi 和 SQL Server</span><span class="muted">2019-06-26</span></a></li> <li><a href="https://www.ipshop.xyz/9049.html"><span class="text">電線電纜的平方數及平方數和電流的換算公式</span><span class="muted">2018-04-02</span></a></li> <li><a href="https://www.ipshop.xyz/1250.html"><span class="text">實體 :手把手教你用PyTorch快速準確地建立神經網路(附4個學習用例)</span><span class="muted">2019-02-02</span></a></li> <li><a href="https://www.ipshop.xyz/12632.html"><span class="text">小樣本學習(Few-shot Learning)綜述</span><span class="muted">2019-04-01</span></a></li> <li><a href="https://www.ipshop.xyz/1208.html"><span class="text">面試官讓用5種python方法實現字串反轉?對不起我有16種……</span><span class="muted">2019-01-13</span></a></li> <li><a href="https://www.ipshop.xyz/4542.html"><span class="text">黎曼猜想仍舊,素數依然孤獨</span><span class="muted">2018-09-26</span></a></li> </ul></div></div></section> <div class="branding branding-black"> <div class="container"> <h2>分享創造快樂</h2> </div> </div> <footer class="footer"> <div class="container"> <p>© 2024 <a href="https://www.ipshop.xyz">知識星球</a>   <a href="http://www.ipshop.xyz/sitemap.xml">網站地圖</a> </p> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-133465382-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-133465382-1'); </script> </div> </footer> <script> window.jsui={ www: 'https://www.ipshop.xyz', uri: 'https://www.ipshop.xyz/wp-content/themes/dux', ver: '5.0', roll: [], ajaxpager: '0', url_rp: '', qq_id: '', qq_tip: '' }; </script> <script type='text/javascript' src='https://www.ipshop.xyz/wp-content/themes/dux/js/libs/bootstrap.min.js?ver=5.0'></script> <script type='text/javascript' src='https://www.ipshop.xyz/wp-content/themes/dux/js/loader.js?ver=5.0'></script> <script type='text/javascript' src='https://www.ipshop.xyz/wp-includes/js/wp-embed.min.js?ver=4.9.25'></script> </body> </html>