[TOC]
October的所有配置文件都存儲在**config /**目錄中。每個選項都有記錄,因此您可以隨意瀏覽文件并熟悉可用的選項。
## **Web服務器配置**
十月具有應該應用于您的網絡服務器的基本配置。常見的Web服務器及其配置可以在下面找到。
### **Apache配置**
如果您的Web服務器正在運行Apache,則還有一些額外的系統要求:
1. 應該安裝mod\_rewrite
2. 應該打開AllowOverride選項
在某些情況下,您可能需要在`.htaccess`文件中取消注釋此行:
~~~
##
## You may need to uncomment the following line for some hosting environments,
## if you have installed to a subdirectory, enter the name here also.
##
# RewriteBase /
~~~
如果已安裝到子目錄,則還應添加子目錄的名稱:
~~~
RewriteBase /mysubdirectory/
~~~
### **Nginx配置**
在Nginx中配置您的網站需要進行一些小的更改。
`nano /etc/nginx/sites-available/default`
在**服務器**部分中使用以下代碼。如果已將October安裝到子目錄中,請將第一個`/`位置指令替換為安裝在October下的目錄:
~~~
location / {
# Let OctoberCMS handle everything by default.
# The path not resolved by OctoberCMS router will return OctoberCMS's 404 page.
# Everything that does not match with the whitelist below will fall into this.
rewrite ^/.*$ /index.php last;
}
# Pass the PHP scripts to FastCGI server
location ~ ^/index.php {
# Write your FPM configuration here
}
# Whitelist
## Let October handle if static file not exists
location ~ ^/favicon\.ico { try_files $uri /index.php; }
location ~ ^/sitemap\.xml { try_files $uri /index.php; }
location ~ ^/robots\.txt { try_files $uri /index.php; }
location ~ ^/humans\.txt { try_files $uri /index.php; }
## Let nginx return 404 if static file not exists
location ~ ^/storage/app/uploads/public { try_files $uri 404; }
location ~ ^/storage/app/media { try_files $uri 404; }
location ~ ^/storage/temp/public { try_files $uri 404; }
location ~ ^/modules/.*/assets { try_files $uri 404; }
location ~ ^/modules/.*/resources { try_files $uri 404; }
location ~ ^/modules/.*/behaviors/.*/assets { try_files $uri 404; }
location ~ ^/modules/.*/behaviors/.*/resources { try_files $uri 404; }
location ~ ^/modules/.*/widgets/.*/assets { try_files $uri 404; }
location ~ ^/modules/.*/widgets/.*/resources { try_files $uri 404; }
location ~ ^/modules/.*/formwidgets/.*/assets { try_files $uri 404; }
location ~ ^/modules/.*/formwidgets/.*/resources { try_files $uri 404; }
location ~ ^/modules/.*/reportwidgets/.*/assets { try_files $uri 404; }
location ~ ^/modules/.*/reportwidgets/.*/resources { try_files $uri 404; }
location ~ ^/plugins/.*/.*/assets { try_files $uri 404; }
location ~ ^/plugins/.*/.*/resources { try_files $uri 404; }
location ~ ^/plugins/.*/.*/behaviors/.*/assets { try_files $uri 404; }
location ~ ^/plugins/.*/.*/behaviors/.*/resources { try_files $uri 404; }
location ~ ^/plugins/.*/.*/reportwidgets/.*/assets { try_files $uri 404; }
location ~ ^/plugins/.*/.*/reportwidgets/.*/resources { try_files $uri 404; }
location ~ ^/plugins/.*/.*/formwidgets/.*/assets { try_files $uri 404; }
location ~ ^/plugins/.*/.*/formwidgets/.*/resources { try_files $uri 404; }
location ~ ^/plugins/.*/.*/widgets/.*/assets { try_files $uri 404; }
location ~ ^/plugins/.*/.*/widgets/.*/resources { try_files $uri 404; }
location ~ ^/themes/.*/assets { try_files $uri 404; }
location ~ ^/themes/.*/resources { try_files $uri 404; }
~~~
### **Lighttpd配置**
如果您的網絡服務器正在運行Lighttpd,您可以使用以下配置來運行OctoberCMS。使用您喜歡的編輯器打開您的站點配置文件。
`nano /etc/lighttpd/conf-enabled/sites.conf`
將以下代碼粘貼到編輯器中,然后更改**主機地址**和**server.document-root**以匹配您的項目。
~~~
$HTTP["host"] =~ "domain.example.com" {
server.document-root = "/var/www/example/"
url.rewrite-once = (
"^/(plugins|modules/(system|backend|cms))/(([\w-]+/)+|/|)assets/([\w-]+/)+[-\w^&'@{}[\],$=!#().%+~/ ]+\.(jpg|jpeg|gif|png|svg|swf|avi|mpg|mpeg|mp3|flv|ico|css|js|woff|ttf)(\?.*|)$" => "$0",
"^/(system|themes/[\w-]+)/assets/([\w-]+/)+[-\w^&'@{}[\],$=!#().%+~/ ]+\.(jpg|jpeg|gif|png|svg|swf|avi|mpg|mpeg|mp3|flv|ico|css|js|woff|ttf)(\?.*|)$" => "$0",
"^/storage/app/uploads/public/[\w-]+/.*$" => "$0",
"^/storage/temp/public/[\w-]+/.*$" => "$0",
"^/(favicon\.ico|robots\.txt|sitemap\.xml)$" => "$0",
"(.*)" => "/index.php$1"
)
}
~~~
### **IIS配置**
如果您的Web服務器正在運行Internet信息服務(IIS),則可以在**web.config**配置文件中使用以下命令來運行OctoberCMS。
~~~
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="OctoberCMS to handle all non-whitelisted URLs" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="^/.well-known/*" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="^/storage/app/uploads/.*" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="^/storage/app/media/.*" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="^/storage/temp/public/.*" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="^/themes/.*/(assets|resources)/.*" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="^/plugins/.*/(assets|resources)/.*" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="^/modules/.*/(assets|resources)/.*" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
~~~
## **應用配置**
### **調試模式**
調試設置可在`config/app.php`配置文件中找到,并帶有`debug`參數,默認情況下處于啟用狀態。
啟用后,此設置將顯示詳細的錯誤消息以及其他調試功能。雖然在開發過程中很有用,但在實時生產站點中使用時,應始終禁用調試模式。這可以防止將潛在的敏感信息顯示給最終用戶。
啟用時,調試模式使用以下功能:
1. 顯示[詳細的錯誤頁面](#666)。
2. 失敗的用戶身份驗證提供了特定原因。
3. 默認情況下,[合并資產](#666)不會縮小。
4. 默認情況下禁用[安全模式](#666)。
> **要點**:始終將`app.debug`設置設置`false`為生產環境。
### **安全模式**
安全模式設置可在`config/cms.php`配置文件中找到,并帶有`enableSafeMode`參數。默認值為`null`。
如果啟用了安全模式,出于安全原因,CMS模板中的PHP代碼部分將被禁用。如果設置為`null`,則在禁用[調試模式](#122)時安全模式打開。
### **CSRF保護**
October提供了一種簡單的方法來保護您的應用程序免受跨站點請求偽造。首先,隨機令牌放在用戶的會話中。然后,當使用[開始表單標記時,](#666)將令牌添加到頁面并隨每個請求一起提交。
雖然默認情況下啟用CSRF保護,但您可以使用配置文件中的`enableCsrfProtection`參數禁用它`config/cms.php`。
### **Bleeding edge 更新**
October平臺和一些市場插件將分兩個階段實施變更,以確保平臺的整體穩定性和完整性。這意味著除了默認的*穩定版本*之外,它們還有一個*測試**版本*。
您可以通過更改配置文件中的`edgeUpdates`參數來指示平臺更喜歡來自市場的測試版本`config/cms.php`。
~~~
/*
|--------------------------------------------------------------------------
| Bleeding edge updates
|--------------------------------------------------------------------------
|
| If you are developing with October, it is important to have the latest
| code base, set this value to 'true' to tell the platform to download
| and use the development copies of core files and plugins.
|
*/
'edgeUpdates' => false,
~~~
> **注意:**對于插件開發人員,我們建議通過“插件設置”頁面為市場上列出的插件啟用**測試更新**。
>
> **注意:**如果使用[Composer](#666)管理更新,請`composer.json`使用以下內容替換文件中的默認OctoberCMS要求,以便直接從開發分支下載更新。
~~~
"october/rain": "dev-develop as 1.0",
"october/system": "dev-develop",
"october/backend": "dev-develop",
"october/cms": "dev-develop",
"laravel/framework": "5.5.*@dev",
~~~
### **使用公用文件夾**
為了在生產環境中獲得最高安全性,您可以將Web服務器配置為使用**公共/**文件夾以確保只能訪問公共文件。首先,您需要使用該`october:mirror`命令生成公用文件夾
~~~
php artisan october:mirror public/
~~~
這將在項目的基本目錄中創建一個名為**public /**的新目錄,從此處您應該修改Web服務器配置以將此新路徑用*作主*目錄,也稱為*wwwroot*。
> **注意**:可能需要使用系統管理員或*sudo*權限執行上述命令。它也應該在每次系統更新后或安裝新插件時執行。
## **環境配置**
### **定義基礎環境**
根據運行應用程序的環境來設置不同的配置值通常很有用。您可以通過設置`APP_ENV`環境變量來實現,默認情況下,它設置為**生產**環境變量。有兩種常用方法可以更改此值:
1. `APP_ENV`直接使用您的網絡服務器設置值。
例如,在Apache中,可以將此行添加到`.htaccess`或`httpd.config`文件中:
~~~
SetEnv APP_ENV "dev"
~~~
2. 使用以下內容在根目錄中創建**.env**文件:
~~~
APP_ENV=dev
~~~
在上述兩個示例中,環境都設置為新值`dev`。現在可以在路徑**config / dev中**創建配置文件,并覆蓋應用程序的基本配置。
例如,要`dev`僅為環境使用不同的MySQL數據庫,請使用以下內容創建名為**config / dev / database.php**的文件:
~~~
<?php
return [
'connections' => [
'mysql' => [
'host' => 'localhost',
'port' => '',
'database' => 'database',
'username' => 'root',
'password' => ''
]
]
];
~~~
### **域驅動環境**
October支持使用特定主機名檢測到的環境。您可以將這些主機名放在環境配置文件中,例如**config / environment.php**。
使用下面的文件內容,當通過**global.website.tld**訪問應用程序時,環境將被設置為`global`,對于其他環境也是如此。
~~~
<?php
return [
'hosts' => [
'global.website.tld' => 'global',
'local.website.tld' => 'local',
]
];
~~~
### **轉換為DotEnv配置**
作為[基本環境配置](#175)的替代方法,您可以在環境中放置常用值,而不是使用配置文件。然后使用[DotEnv](https://github.com/vlucas/phpdotenv)語法訪問配置。運行`october:env`命令將公共配置值移動到環境中:
~~~
php artisan october:env
~~~
這將在項目根目錄中創建一個**.env**文件,并修改配置文件以使用`env`幫助程序功能。第一個參數包含在環境中找到的鍵名,第二個參數包含可選的默認值。
~~~
'debug' => env('APP_DEBUG', true),
~~~
您的`.env`文件不應該提交給應用程序的源代碼控制,因為使用您的應用程序的每個開發人員或服務器都可能需要不同的環境配置。
- 安裝程序
- 安裝
- 配置
- CMS
- 主題
- 頁面
- 部件
- 布局
- 內容
- 組件
- 媒體
- 標記指南
- AJAX
- 介紹
- 事件處理
- 更新部件
- 數據屬性API
- JavaScript API
- 額外特征
- 主題
- 開發主題
- 插件
- 注冊
- 版本
- 使用Composer
- 構建組件
- 設置和配置
- 本地化
- 任務調度
- 擴展插件
- 后臺
- 控制器和AJAX
- 視圖和部件
- 小工具
- 表單
- 列表
- 關聯
- 重新排序
- 導入導出
- 用戶和權限
- 用戶界面指南
- 數據庫
- 基本用法
- 結構
- 查詢構造器
- 模型
- 關聯
- 附件
- 集合
- 訪問器和修改器
- 序列化
- 特性
- 行為
- 服務
- 應用
- 行為
- 緩存
- 集合
- 錯誤&日志
- 事件
- 表單&HTML
- 文件系統/CDN
- 哈希&加密
- 助手函數
- 郵件
- 分頁
- 分析器
- 隊列
- 請求&輸入
- 響應&視圖
- 路由
- Session
- 驗證
- 控制臺
- 命令
- 腳手架
- 開發
- API文檔
- 附錄
- 單元測試
- 質量指南
- 開發指南