寶塔面板安裝Webman項(xiàng)目
0. 環(huán)境要求
- PHP >= 8.1
1. 創(chuàng)建項(xiàng)目
cd /www/wwwroot
composer create-project workerman/webman
2. 設(shè)置網(wǎng)站
注意:
寶塔會(huì)自動(dòng)守護(hù)進(jìn)程,啟動(dòng)命令為php /www/wwwroot/webman/start.php start
,不加-d
參數(shù),否則無法啟動(dòng)
3. 配置站點(diǎn)
4. 設(shè)置運(yùn)行目錄
注意:
為了系統(tǒng)安全,運(yùn)行目錄必須設(shè)置為/public
,錯(cuò)誤的設(shè)置可能會(huì)導(dǎo)致敏感文件被外網(wǎng)訪問
5. 設(shè)置偽靜態(tài)
# 將請(qǐng)求轉(zhuǎn)發(fā)到webman
location ^~ / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Connection "";
if (!-f $request_filename){
proxy_pass http://127.0.0.1:8787;
}
}
# 拒絕訪問所有以 .php 結(jié)尾的文件
location ~ \.php$ {
return 404;
}
# 允許訪問 .well-known 目錄
location ~ ^/\.well-known/ {
allow all;
}
# 拒絕訪問所有以 . 開頭的文件或目錄
location ~ /\. {
return 404;
}
6. 給runtime可寫權(quán)限
chmod -R 777 /www/wwwroot/webman/runtime
備注
正常不需要此步驟,疑似寶塔bug,服務(wù)設(shè)置的www
用戶啟動(dòng),但實(shí)際是daemon用戶啟動(dòng),導(dǎo)致無法寫入runtime目錄
7. 重啟服務(wù)
8. 訪問站點(diǎn)
訪問站點(diǎn) http://example.com
即可看到webman的歡迎頁面
故障排查
-
站點(diǎn)無法訪問提示 502 Bad Gateway
檢查webman是否啟動(dòng) -
weman啟動(dòng)失敗
如圖所示,檢查是否有錯(cuò)誤日志