根據httpd-2.4.18-x64-vc11-r2版本的httpd.conf去記錄的。
1. Define定義常量,定義了一個名字為SRVROOT的常量
語法 常量名 常量的值
Define SRVROOT "I:/server/httpd/Apache24"
在文檔的其他地方引用該常量的方法:
ServerRoot "${SRVROOT}" 定義服務器根目錄
DocumentRoot "${SRVROOT}/htdocs" 定義網站根目錄
上例是通過在頂端定義了一個常量,在下面引用該常量來訪問,好處不用多說了,之后改動只要改這一個即可,其他的都是相對路徑了。
2. Listen 80,添加監聽的端口號,可以同時監聽多個。
3. Dynamic Shared Object (DSO) Support動態共享對象支持。即打開#號和關閉#,來控制模塊是否加載,這個不一一說,以后再慢慢研究。
4. ServerAdmin admin@example.com當服務器出現錯誤的時候,發送郵件到該地址,這個地址顯示在服務器生成的頁面。
5. ServerName localhost:80 服務器名稱
6. 訪問服務器文件系統的權限設置。
<Directory />
AllowOverride none
# Require all denied
Require all granted 允許ip訪問
</Directory>
7. 網站訪問的根目錄及權限設置
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks 允許列出文件目錄
AllowOverride None 是否允許重寫
Require all granted 控制誰可以從服務器獲得資料
</Directory>
8. 服務器默認訪問的文件名字
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
php的要在后面加上index.php或者server.php等。
9. 定義不被允許訪問的文件,可通過正則匹配文件名
<Files ".ht*">
Require all denied
</Files>
10. 定義錯誤日志文件
ErrorLog "logs/error.log"
11. 日志級別記錄控制。
LogLevel warn(可包括debug, info, notice, warn, error, crit,alert, emerg.)
虛擬機配置
服務器默認的是關閉的,在http.conf中對應的代碼是這樣的。
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
打開下面一句前面的#號,即可。虛擬機的配置在httpd-vhosts.conf文件中。可在conf下的extra文件夾里面找到。
在里面添加如下形式的:
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot "${SRVROOT}/docs/dummy-host.example.com" 項目在本機的目錄
# ServerName dummy-host.example.com 訪問輸入的地址URL
# ServerAlias www.dummy-host.example.com 訪問的別名
# ErrorLog "logs/dummy-host.example.com-error.log" 錯誤日志記錄文件
# CustomLog "logs/dummy-host.example.com-access.log" common 虛擬主機訪問的日志
#</VirtualHost>
虛擬機一般分為基於IP、基於主機名、和基於端口號的方式三種。配置就不多說了,可以參考其他的。
別名alias_module
Alias /web "${SRVROOT}/htdocs/yii"
添加一個到別名,指向指定的目錄即可通過,http://localhost/web來訪問放在其他地方的yii。
指定的訪問路徑必須配置一下:
<Directory "${SRVROOT}/htdocs/yii">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>