本文完整记录了如何在 CyberPanel + OpenLiteSpeed(OLS) 中反代本机 Docker 服务。
示例:反代 PanSou 容器的127.0.0.1:8080。
目录
📌 前言:为什么反代会 500?
OpenLiteSpeed(OLS)与 Nginx 不同。Nginx 的 proxy_pass 可直接反代,但 OLS 需要:
- 必须定义 External App(后端 Web Server)
- RewriteRule 的
[P]只是触发反代,不包含后端信息 - 默认禁止反代到
127.0.0.1,必须开启enableIpInProxy 1 - WebSocket 默认关闭,需要
enableWebSocket 1
如果没有正确配置,就会出现:
500 Internal Server Error
Proxy target is not defined on external application list
🧩 一、Docker 服务示例
PanSou Docker 配置示例:
ports:
- "8080:80"
浏览器访问:
http://服务器IP:8080
可以正常打开。
🛠 二、在 CyberPanel 设置反代 Rewrite Rules
打开:
CyberPanel → Websites → Manage → Rewrite Rules
内容写:
RewriteEngine On
RewriteRule ^(.*)$ http://127.0.0.1:8080/$1 [P,L]
⚠️ 注意:
- Rewrite Rules 不写进 vHost Conf
- Rewrite Rules 必须单独设置
⚙ 三、编辑 vHost Conf(开启本机反代 + WebSocket)
打开:
CyberPanel → Websites → Manage → vHost Conf
在文件最底部(但 不在任何 {} 里面)添加:
enableIpInProxy 1
enableWebSocket 1
完整正确的 vHost Conf 示例:
docRoot $VH_ROOT/public_html
vhDomain $VH_NAME
vhAliases www.$VH_NAME
adminEmails nfksuk@gmail.com
enableGzip 1
enableIpGeo 1
errorlog $VH_ROOT/logs/$VH_NAME.error_log {
useServer 0
logLevel WARN
rollingSize 10M
}
accesslog $VH_ROOT/logs/$VH_NAME.access_log {
useServer 0
logFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
logHeaders 5
rollingSize 10M
keepDays 10
compressArchive 1
}
index {
useServer 0
indexFiles index.php, index.html
}
scripthandler {
add lsapi:soxyz7323 php
}
extprocessor soxyz7323 {
type lsapi
address UDS://tmp/lshttpd/soxyz7323.sock
maxConns 10
env LSAPI_CHILDREN=10
initTimeout 600
retryTimeout 0
persistConn 1
pcKeepAliveTimeout 1
respBuffer 0
autoStart 1
path /usr/local/lsws/lsphp82/bin/lsphp
extUser soxyz7323
extGroup soxyz7323
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 400
procHardLimit 500
}
###############################################
# 🔥 反向代理到 Docker HTTP 后端 (PanSou:8080)
###############################################
extprocessor 127.0.0.1:8080 {
type proxy
address 127.0.0.1:8080
maxConns 100
initTimeout 60
retryTimeout 0
respBuffer 0
}
context /.well-known/acme-challenge {
location /usr/local/lsws/Example/html/.well-known/acme-challenge
allowBrowse 1
rewrite {
enable 0
}
addDefaultCharset off
}
rewrite {
enable 1
autoLoadHtaccess 1
}
vhssl {
keyFile /etc/letsencrypt/live/$VH_NAME/privkey.pem
certFile /etc/letsencrypt/live/$VH_NAME/fullchain.pem
certChain 1
enableECDHE 1
renegProtection 1
sslSessionCache 1
enableSpdy 15
enableStapling 1
ocspRespMaxAge 86400
}
module cache {
storagePath /usr/local/lsws/cachedata/$VH_NAME
}
###############################################
# 🔥 必须保留的反代功能:真实 IP + WebSocket
###############################################
enableIpInProxy 1
enableWebSocket 1
如果无法直接编辑则进入服务器编辑:
nano /usr/local/lsws/conf/vhosts/so.886699.xyz/vhost.conf
复制粘贴进去保存即可!
🌐 四、最关键步骤:添加 External App(反代后端)
打开 OLS 控制台:
http://服务器IP:7080
如果不知道账号密码:
首先,在 SSH 中运行以下命令来设置 Web 管理控制台的登录信息。
/usr/local/lsws/admin/misc/admpass.sh
进入:
Virtual Hosts → so.886699.xyz → External App → Add
填写如下(必须完全一致):
| 字段 | 值 |
|---|---|
| Name | 127.0.0.1:8080 |
| Type | Web Server |
| Address | 127.0.0.1:8080 |
| Max Connections | 100 |
| Initial Request Timeout | 60 |
| Retry Timeout | 0 |
保存。
🔄 五、重启 OpenLiteSpeed
执行:
systemctl restart lsws
必要!否则配置不会生效。
🧪 六、测试反代
访问:
https://so.886699.xyz/
应该出现 PanSou 页面。
🛑 七、故障排查(500 专用)
查看 OLS 日志:
cat /usr/local/lsws/logs/error.log | tail -n 50
常见错误:
❌ Proxy target is not defined
解决:External App 未创建(必须添加)
❌ vHost Conf block 语法错误
解决:检查是否把 enableIpInProxy 放进 {} 里
❌ RewriteRule 写错
必须是:
RewriteRule ^(.*)$ http://127.0.0.1:8080/$1 [P,L]
🎉 八、最终成功状态
完成上述步骤后:
- Rewrite Rules 正常
- vHost Conf 开启本机反代
- External App 定义后端服务
- OLS 重启成功
访问域名将完美显示 Docker 服务内容。
