說明
應(yīng)用程序目錄結(jié)構(gòu)適用于Yii 2.x 版本鹅髓,注:Yii 2.x 必須運行在 PHP 5.4+ 以上的環(huán)境。
代碼git
https://github.com/tusamuel/Yii2.x-Code-Template
該目錄結(jié)構(gòu)支持特性
- 公共靜態(tài)文件目錄static/度秘,方便單獨web緩存優(yōu)化或CDN加速;
- 公共數(shù)據(jù)文件目錄data/瞻鹏,方便數(shù)據(jù)目錄單獨掛載尖滚;
- 公共的配置文件目錄config/,公共日志目錄runtime/庐氮,方便部署和日常運維语稠;
- 獨立的vendor/、source/弄砍、frontend/仙畦、backend/、console/ ,系統(tǒng)權(quán)限和web訪問權(quán)限分離音婶;
- 包含國際化語言包(source/messages/**/**.php)议泵;
- 包含主題(僅前臺系統(tǒng),source/frontend/themes/**/views/**)
- 非生產(chǎn)環(huán)境代碼桃熄,tests/、tools/
目錄結(jié)構(gòu)
根目錄文件
<pre>
build.xml Jenkins 配置文件(如果未使用Jenkins集成型奥,可忽略本文件)
</pre>
vendor/
框架和組件的源碼目錄(composer默認安裝目錄)
source/
程序源碼目錄
<pre>
common/ 公共源碼
assets/
models/
components/
frontend/ 前臺應(yīng)用源碼
assets/
models/
controllers/
views/
themes/ 主題目錄
backend/ 后臺應(yīng)用源碼
assets/
models/
controllers/
views/
console/ 腳本應(yīng)用源碼
models/
controllers/
messages/ 國際化語言包
</pre>
config/
程序配置目錄
<pre>
common/ 公共配置
frontend/ 前臺應(yīng)用配置
backend/ 后臺應(yīng)用配置
console/ 命令行應(yīng)用配置
</pre>
static/
靜態(tài)文件目錄瞳收,包括css、js厢汹、images
<pre>
common/ 公共靜態(tài)文件
frontend/ 前臺應(yīng)用靜態(tài)文件
backend/ 后臺應(yīng)用靜態(tài)文件
</pre>
data/
用戶數(shù)據(jù)目錄(用戶上傳數(shù)據(jù))
runtime/
程序日志目錄(yii應(yīng)用生成)
<pre>
frontend/ 前臺日志目錄
backend/ 后臺日志目錄
console/ 腳本日志目錄
</pre>
根目錄文件frontend/
前臺應(yīng)用web目錄
根目錄文件backend/
后臺應(yīng)用web目錄
說明console/
命令行應(yīng)用目錄
tests/
測試腳本目錄(僅用于開發(fā)和測試螟深,不部署到生產(chǎn)環(huán)境)
tools/
工具目錄(僅用于應(yīng)用初始化,部署完后應(yīng)刪除)
<pre>
composer.phar
composer.json
composer.lock
init
init.bat
requirement.php
environments/
</pre>
目錄的系統(tǒng)權(quán)限
目錄的系統(tǒng)權(quán)限烫葬,通過/path/tools/init 初始化工具 自動完成界弧,詳見[Yii 2.x 的應(yīng)用初始化工具](待更新)。
源碼目錄
這些目錄不允許web修改搭综,也不允許shell執(zhí)行垢箕,目錄所有者是root:root 或jenkins_publisher:jenkins_publisher(或其他源碼發(fā)布管理組/用戶),目錄權(quán)限為:755兑巾,文件權(quán)限為:644
<pre>
vendor/
source/
config/
static/
frontend/
backend/
</pre>
web目錄
這些目錄允許web修改条获,但不允許shell執(zhí)行,及子目錄權(quán)限所有者是nobody:root 或 nobody:jenkins_publisher蒋歌,目錄權(quán)限為:755帅掘,文件權(quán)限為:644
<pre>
data/
runtime/
</pre>
命令行應(yīng)用入口
<pre>
console/
</pre>
目錄的web訪問權(quán)限
目錄的web訪問權(quán)限通過nginx(或apache)配置進行限制委煤,詳見 nginx 配置 部分
僅允許特定的入口文件執(zhí)行php(默認 index.php)
<pre>
/path/index.php (軟鏈,指向 /path/frontend/index.php)
/path/frontend/index.php
/path/backend/index.php
</pre>
允許web訪問的目錄
除了以下目錄外修档,其他目錄均無web訪問的權(quán)限碧绞,并返回404錯誤
<pre>
assets/ (軟鏈,指向 /path/frontend/assets/)
data/
static/
frontend/
backend/
</pre>
禁止通過web執(zhí)行腳本文件的目錄
在允許web訪問的目錄中吱窝,以下目錄不能執(zhí)行任何的腳本文件讥邻,包括php、jsp癣诱、sh等腳本文件计维,并返回403
<pre>
data/
static/
frontend/assets/
backend/assets/
</pre>
nginx配置(僅location 部分)
<pre>
index index.html index.htm index.php;
#隱藏index.php
location / {
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
#web可訪問,但禁止腳本執(zhí)行的目錄
location ~\* ^/(frontend|backend)/assets/.\*\.(php|php5|asp|aspx|py|pl|cgi|sh)$ {
return 404;
break;
}
#web可訪問撕予,但禁止腳本執(zhí)行的目錄
location ~\* ^/(static|data|assets)/.\*\.(php|php5|asp|aspx|py|pl|cgi|sh)$ {
return 404;
break;
}
#禁止web訪問的目錄
location ~\* ^/(config|runtime|source|verdor|console|tests)/ {
return 404;
break;
}
#允許frontend或backend目錄下的index.php文件
location ~\* ^/(frontend|backend)/index\.php$ {
try_files $uri =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
#允許根目錄下的index.php文件
location ~\* ^/index\.php$ {
try_files $uri =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
</pre>