啟用與停用網站的方法
a2ensite 站点名 a2dissite 站点名
基於名字的(透過網域來區分)的虛擬主機
安裝好apache以後預設有一個叫default的虛擬主機。新建虛擬主機時可以直接複製預設虛擬主機的設定文件,在其基礎上修改新虛擬主機的設定參數。
#copy /etc/apache2/site-available/default /etc/apache2/site-available/sitename
測試環境
作業系統:Ubuntu Server 12.04 LTS
測試機位址:10.39.6.59
測試機網域:*.example.com
機器上設定多個網域名稱或主機名稱時,我們就要用到基於名稱的虛擬主機了。那麼要如何進行設定呢?這就是本指南想解決的問題 了。在 Ubuntu 的 /etc/apache2/ 目錄下有個 Apache2 的主設定檔 apache2.conf。在該檔案中我們可以看到下列欄位:# Include the virtual host configurations: Include /etc/apache2/sites-enabled/[^.#]*(12.04版本里无[^.#]*)這行的意思表示該檔案包含了/etc/apache2/sites-enabled/ 目錄中檔案名稱不含"." 或"#" 這兩個字元的所有文件。而當我們列出該目錄的文件時,發現只有一個000-default 的軟鏈接文件,實際連接的是/etc/apache2/sites-available 目錄中的default 文件,不難看出該文件的文件名中並不包含"." 或"#"。所以這個檔案當然是要被設定檔 apache2.conf 所包含的了。打開該文件,發現它其實是一個虛擬主機的配置文件,不過由於該文件中的虛擬主機為 *,所以它實際上是一個通用配置文件。如果我們要建立虛擬主機的話,那麼就要把該檔案改成如下所示:
<VirtualHost *:80> ServerName www.firehare.com ServerAdmin admin@mail.firehare.com DocumentRoot /var/www/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny Allow from all # This directive allows us to have apache2's default start page # in /apache2-default/, but still have / go to the right place # Commented out for Ubuntu #RedirectMatch ^/$ /apache2-default/ </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined ServerSignature On Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>下面我們來分析一下上面這段設定中與虛擬主機相關的設定語句:`NameVirtualHost :80`:表示我們要做的是一個基於名稱的虛擬主機,監聽的連接埠為80.`
<VirtualHost *:80> ServerName edunuke.example.com ServerAdmin edunuke@mail.example.com DocumentRoot "/var/www/edunuke/" ErrorLog "/var/log/apache2/edunuke_errors.log" CustomLog "/var/log/apache2/edunuke_accesses.log" common </VirtualHost>設定的具體含義同上面的相似,這是我就不再多說了。然後再執行指令:
sudo a2ensite edunuke這樣的話,虛擬主機網站 edunuke.example.com 就已經安裝好了。這時你也可以在 /etc/apache2/sites-enabled/ 目錄中發現多了一個到 /etc/apache2/sites-available/edunuke 的軟連結。接下來就是將Apache2 重新啟動來讓虛擬主機網站運作起來:
sudo /etc/init.d/apache2 restart 这里可以使用reload 重新加载這樣你在瀏覽器上輸入edunuke.example.com 的話,就會被指向/var/www/edunuke 目錄了,而輸入其他指向本機的網域名稱都會指到預設配置中的/var/www 目錄中。熟悉 Apache2 的朋友會問為什麼這樣麻煩,放在一個檔案裡不也是可以嗎?為什麼要用兩份文件呢?其實很簡單,因為如果我要對 edunuke 站點進行維護時,我只要運行命令:
sudo a2dissite edunuke sudo /etc/init.d/apache2 restart即可,這樣既可以維護 edunuke 這個站點,同時還不影響其他站點的正常運行。 高級配置
上面谈了一下简单的虚拟主机配置方法。这个基本上能满足我们大部分的需要。但如果要是安装 Zope+Plone 的话,上面的这点设置是远远不够的,由于 Zope+Plone 结构所采用的端口并非是80端口,所以我们还得做端口重定向。为了能够做这个,我们得激活 Rewrite 和 Proxy 两个模块。激活模块很简单,同站点配置目录一样,在 Apache2 中也有两个模块配置目录:mods-available 和 mods-enabled。在 mods-available 目录中的是所有可用的模块,而在 mods-enabled 目录中的则是已被安装到 Apache2 中的模块。由于在 mods-available 目录中已经有了 Rewrite 和 Proxy 模块的配置引导文件,所以只需要简单地将其安装到 Apache2 中即可。使用命令:
sudo a2enmod rewrite sudo a2enmod proxy
然后,添加虚拟主机站点 plone.example.com,同 edunuke 站点创建相似在/etc/apache2/sites-available/ 目录中建立一个文件 plone。显然这个文件名中是没有 "." 或 "#" 这两个字符的了。然后编辑该文件:
<VirtualHost plone.example.com:80> ServerName plone.example.com ServerAdmin plone@mail.example.com ErrorLog "/var/log/apache2/plone_errors.log" CustomLog "/var/log/apache2/plone_accesses.log" common RewriteEngine on RewriteRule ^/(.*) http://127.0.0.1:8081/VirtualHostBase/http/plone.firehare.com:80/plone/VirtualHostRoot/$1 [L,P] <Proxy *> Order Deny,Allow Deny from all Allow from all </Proxy> </VirtualHost>
这样就安装好了 plone.example.com 虚拟主机站点,可以在浏览器中地址栏中输入 http://plone.example.com 就可以重定向到 Zope+Plone 站点去了。

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

phpisusedforsendendemailsduetoitsignegrationwithservermailservicesand andexternalsmtpproviders,自動化intifications andMarketingCampaigns.1)設置設置yourphpenvenvironnvironnvironmentwithaweberswithawebserverserververandphp,確保themailfunctionisenabled.2)useabasicscruct

發送電子郵件的最佳方法是使用PHPMailer庫。 1)使用mail()函數簡單但不可靠,可能導致郵件進入垃圾郵件或無法送達。 2)PHPMailer提供更好的控制和可靠性,支持HTML郵件、附件和SMTP認證。 3)確保正確配置SMTP設置並使用加密(如STARTTLS或SSL/TLS)以增強安全性。 4)對於大量郵件,考慮使用郵件隊列系統來優化性能。

CustomHeadersheadersandAdvancedFeaturesInphpeMailenHanceFunctionalityAndreliability.1)CustomHeadersheadersheadersaddmetadatatatatataatafortrackingandCategorization.2)htmlemailsallowformattingandttinganditive.3)attachmentscanmentscanmentscanbesmentscanbestmentscanbesentscanbesentingslibrarieslibrarieslibrariesliblarikelikephpmailer.4)smtppapapairatienticationaltication enterticationallimpr

使用PHP和SMTP發送郵件可以通過PHPMailer庫實現。 1)安裝並配置PHPMailer,2)設置SMTP服務器細節,3)定義郵件內容,4)發送郵件並處理錯誤。使用此方法可以確保郵件的可靠性和安全性。

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

使用依賴注入(DI)的原因是它促進了代碼的松耦合、可測試性和可維護性。 1)使用構造函數注入依賴,2)避免使用服務定位器,3)利用依賴注入容器管理依賴,4)通過注入依賴提高測試性,5)避免過度注入依賴,6)考慮DI對性能的影響。

phpperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovessetimes.2)優化


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

Dreamweaver CS6
視覺化網頁開發工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

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