nginx 設定
說明在 nginx 上執行 Zittme 所需的設定。若您使用 Apache,則不需要這份文件。發行版中的 .htaccess 會自動處理。
最簡單的方法:設定助手
Zittme 提供產生 nginx 設定的助手。請使用下列任一方便的方式。
- 安裝精靈的環境檢查畫面:若短網址(rewrite)尚未設定,會偵測伺服器環境並產生專屬設定與套用指令。複製貼上即可。
- 管理員 > 系統設定中的短網址助手:安裝後也能使用相同功能。
- 一次套用的指令碼:發行版中的
common/scripts/setup-nginx.sh
若要自行設定,請參考以下內容。
設定檔位置
| 發行版 | 網站設定 |
|---|---|
| Ubuntu / Debian | /etc/nginx/sites-available/(以符號連結放到 sites-enabled/ 啟用) |
| CentOS / RHEL | /etc/nginx/conf.d/ |
伺服器區塊範例
發行版的 common/manual/server_config/zittme-nginx.conf 中包含完整規則。基本骨架如下。
server {
listen 80;
server_name example.com;
root /var/www/mysite;
index index.php index.html;
client_max_body_size 32m;
# 여기에 zittme-nginx.conf 의 규칙(차단·rewrite)을 넣거나 include 합니다
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
}root是 Zittme 的安裝路徑,index中必須包含index.php。client_max_body_size是允許上傳的容量。請配合附件大小調整。- PHP-FPM 通訊端路徑因伺服器而異。可用
ls /run/php/確認,也可以改用連接埠方式(fastcgi_pass 127.0.0.1:9000;)。
注意規則順序
Zittme 的 rewrite 規則中已包含 location / { try_files ... } 區塊。若在網站設定中重複加入相同區塊,就會發生錯誤。 請將封鎖規則(location 區塊)放在 PHP 處理區塊之前。
套用與確認
nginx -t
systemctl reload nginxnginx -t 必須輸出 ok。若有問題,請確認 /var/log/nginx/error.log。
安全封鎖規則
zittme-nginx.conf 中包含禁止從網路直接存取範本・設定・快取檔案的規則。即使自行撰寫設定,也務必加入這些封鎖規則。若遺漏,範本原始檔與內部檔案可能會暴露於外部。