Linux下Apache的設定檔是 /etc/apache2/apache2.conf,Apache在啟動時會自動讀取這個檔案的設定資訊。而其他的一些設定文件,如 httpd.conf等,則是透過Include指令包含進來。
在apache2.conf裡有sites-enabled目錄,而在/etc/apache2下還有一個sites-available目錄,其實,這裡面才是真正的配置文件,而sites- enabled目錄存放的只是一些指向這裡的文件的符號鏈接,你可以用ls /etc/apache2/sites-enabled/來證實一下。
所以,如果apache上配置了多個虛擬主機,每個虛擬主機的設定檔都放在sites-available下,那麼對於虛擬主機的停用、啟用就非常方便了:當在sites -enabled下建立一個指向某個虛擬主機設定檔的連結時,就啟用了它;如果要關閉某個虛擬主機的話,只需刪除對應的連結即可,根本不用去改設定檔。
sudo cp /etc/apache2/sites-avaliable/000-default.conf , 命名为 test.conf
2.修改設定檔:test.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 in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName www.test.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html/test/ ErrorLog /var/www/html/test/error.log CustomLog /var/www/html/test/access.log combined <Directory "/var/www/html/test"> Options FollowSymLinks DirectoryIndex index.php index.html index.htm AllowOverride All #注意这个地方的配置,会影响本地目录下的.htaccess的启用 Order deny,allow Allow from All </Directory> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost>
建立連結檔:
sudo ln -s /etc/apache2/sites-available/test.conf /etc/apache2/sites-enabled/test.conf
或: sudo a2ensite test.conf
#4.重啟apache 伺服器
sudo /etc/init.d/apache2 restart
修改hosts(/etc/hosts)
// 增加一行 127.0.0.1 www.test.com
到這裡基本上就可以正常存取了!
附:如果這裡還需要對目錄級的URL重寫支持,繼續往下:
終端運行
sudo a2enmod
程式提示可供啟動的模組名稱,輸入:rewrite
成功會提示
rewrite already load
修改/etc/apache2/sites-enabled/test.conf (該連結指向的是網站設定檔)
把下的AllowOverride 屬性改為All,保存。 (上面我們已經設定為 All)
重新載入apache
sudo /etc/init.d/apache2 restart
更多Apache相關知識,請造訪Apache使用教學欄位!
以上是linux下apache設定檔在哪裡的詳細內容。更多資訊請關注PHP中文網其他相關文章!

ApacheHTTPServer在現代Web環境中依然重要,因為其穩定性、可擴展性和豐富的生態系統。 1)穩定性和可靠性使其適用於高可用性環境。 2)廣泛的生態系統提供豐富的模塊和擴展。 3)易於配置和管理,即使初學者也能快速上手。

Apache成功的原因包括:1)強大的開源社區支持,2)靈活性和可擴展性,3)穩定性和可靠性,4)廣泛的應用場景。通過社區的技術支持和共享,Apache提供了靈活的模塊化設計和配置選項,確保了其在各種需求下的適應性和穩定性,廣泛應用於從個人博客到大型企業網站的不同場景。

Apachebecamefamousduetoitsopen-sourcenature,modulardesign,and strongcommunitysupport.1)ITSOPEN-SOPEN-SOURCEMODELANDELANDPERMISSIVEPEPEPIRENESENESCORENDECERAGEDWIDEDWIDESPREADADOPTION.2)tHEMODECTURALACTARACTIOLARACTURARACTURARACTURARACTURARACTERTURELALARTARACTEXIVEDEDENEXIVECUSTOMASTACTOPATAPATATSICATS.3)

Apache的性能和靈活性使其在Web服務器中脫穎而出。 1)性能優勢體現在高效處理和可擴展性,通過多進程和多線程模型實現。 2)靈活性源於模塊化設計和配置的靈活性,允許根據需求加載模塊並調整服務器行為。

當 Apache 80 端口被佔用時,解決方法如下:找出佔用該端口的進程並關閉它。檢查防火牆設置以確保 Apache 未被阻止。如果以上方法無效,請重新配置 Apache 使用不同的端口。重啟 Apache 服務。

Apache 無法啟動,原因可能有以下幾點:配置文件語法錯誤。與其他應用程序端口衝突。權限問題。內存不足。進程死鎖。守護進程故障。 SELinux 權限問題。防火牆問題。軟件衝突。

要在 Apache 中設置 CGI 目錄,需要執行以下步驟:創建 CGI 目錄,如 "cgi-bin",並授予 Apache 寫入權限。在 Apache 配置文件中添加 "ScriptAlias" 指令塊,將 CGI 目錄映射到 "/cgi-bin" URL。重啟 Apache。

有 3 種方法可在 Apache 服務器上查看版本:通過命令行(apachectl -v 或 apache2ctl -v)、檢查服務器狀態頁(http://<服務器IP或域名>/server-status)或查看 Apache 配置文件(ServerVersion: Apache/<版本號>)。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器