150 lines
6.1 KiB
Plaintext
150 lines
6.1 KiB
Plaintext
|
|
# ============================================================
|
|||
|
|
# 聊天室 Nginx 生产环境配置(基于宝塔面板)
|
|||
|
|
# 域名:chat.ay.lc
|
|||
|
|
# 支持:Laravel 12 + Laravel Reverb WebSocket 反向代理
|
|||
|
|
# ============================================================
|
|||
|
|
#
|
|||
|
|
# 部署方式:
|
|||
|
|
# 在宝塔面板 → 网站 → chat.ay.lc → 设置 → 配置文件 中,
|
|||
|
|
# 将下方 WebSocket 反向代理部分和 Laravel 伪静态部分
|
|||
|
|
# 粘贴到您现有配置的对应位置即可。
|
|||
|
|
#
|
|||
|
|
# ============================================================
|
|||
|
|
|
|||
|
|
# ═══════════════════════════════════════════════════════════
|
|||
|
|
# 请将下面这段放在 server { } 块的【最外层上方】
|
|||
|
|
# (与 server 同级,不要放在 server 内部)
|
|||
|
|
# ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
map $http_upgrade $connection_upgrade {
|
|||
|
|
default upgrade;
|
|||
|
|
'' close;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# ═══════════════════════════════════════════════════════════
|
|||
|
|
# 请将下面这段放在 server { } 块内部,
|
|||
|
|
# 建议放在 #REWRITE-END 之后,禁止访问敏感文件之前
|
|||
|
|
# ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
# ── Laravel 伪静态规则 ──────────────────────────────────
|
|||
|
|
# 如果宝塔的伪静态配置文件 rewrite/chat.ay.lc.conf 为空,
|
|||
|
|
# 请在宝塔面板 → 网站 → 伪静态 中选择 "laravel5",
|
|||
|
|
# 或者直接在 rewrite/chat.ay.lc.conf 中写入以下内容:
|
|||
|
|
#
|
|||
|
|
# location / {
|
|||
|
|
# try_files $uri $uri/ /index.php?$query_string;
|
|||
|
|
# }
|
|||
|
|
|
|||
|
|
# ⚡ WebSocket 反向代理(核心配置 - 必须添加!)
|
|||
|
|
# Laravel Reverb 监听在 127.0.0.1:8080
|
|||
|
|
# 浏览器通过 /app 和 /apps 路径发起 WebSocket 连接
|
|||
|
|
location /app {
|
|||
|
|
proxy_pass http://127.0.0.1:8080;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
proxy_set_header Connection $connection_upgrade;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
|
|||
|
|
# WebSocket 长连接保活:120秒无数据才断开
|
|||
|
|
proxy_read_timeout 120s;
|
|||
|
|
proxy_send_timeout 120s;
|
|||
|
|
|
|||
|
|
# 关闭缓冲,保证实时性
|
|||
|
|
proxy_buffering off;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
location /apps {
|
|||
|
|
proxy_pass http://127.0.0.1:8080;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
proxy_set_header Connection $connection_upgrade;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
|
|||
|
|
proxy_read_timeout 120s;
|
|||
|
|
proxy_send_timeout 120s;
|
|||
|
|
proxy_buffering off;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ═══════════════════════════════════════════════════════════
|
|||
|
|
# 完整配置合并后的参考样本(方便您核对)
|
|||
|
|
# ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
# map $http_upgrade $connection_upgrade {
|
|||
|
|
# default upgrade;
|
|||
|
|
# '' close;
|
|||
|
|
# }
|
|||
|
|
#
|
|||
|
|
# server
|
|||
|
|
# {
|
|||
|
|
# listen 80;
|
|||
|
|
# listen 443 ssl;
|
|||
|
|
# listen 443 quic;
|
|||
|
|
# http2 on;
|
|||
|
|
# server_name chat.ay.lc;
|
|||
|
|
# index index.php index.html index.htm default.php default.htm default.html;
|
|||
|
|
# root /www/wwwroot/chat.ay.lc/public;
|
|||
|
|
#
|
|||
|
|
# #CERT-APPLY-CHECK--START
|
|||
|
|
# include /www/server/panel/vhost/nginx/well-known/chat.ay.lc.conf;
|
|||
|
|
# #CERT-APPLY-CHECK--END
|
|||
|
|
# include /www/server/panel/vhost/nginx/extension/chat.ay.lc/*.conf;
|
|||
|
|
#
|
|||
|
|
# #SSL-START
|
|||
|
|
# ... (您现有的 SSL 配置保持不变)
|
|||
|
|
# #SSL-END
|
|||
|
|
#
|
|||
|
|
# #ERROR-PAGE-START
|
|||
|
|
# error_page 404 /404.html;
|
|||
|
|
# #ERROR-PAGE-END
|
|||
|
|
#
|
|||
|
|
# #PHP-INFO-START
|
|||
|
|
# include enable-php-84.conf;
|
|||
|
|
# #PHP-INFO-END
|
|||
|
|
#
|
|||
|
|
# #REWRITE-START
|
|||
|
|
# include /www/server/panel/vhost/rewrite/chat.ay.lc.conf;
|
|||
|
|
# #REWRITE-END
|
|||
|
|
#
|
|||
|
|
# # ⚡⚡⚡ 在这里插入 WebSocket 反向代理 ⚡⚡⚡
|
|||
|
|
# location /app {
|
|||
|
|
# proxy_pass http://127.0.0.1:8080;
|
|||
|
|
# proxy_http_version 1.1;
|
|||
|
|
# proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
# proxy_set_header Connection $connection_upgrade;
|
|||
|
|
# proxy_set_header Host $host;
|
|||
|
|
# proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
# proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
# proxy_read_timeout 120s;
|
|||
|
|
# proxy_send_timeout 120s;
|
|||
|
|
# proxy_buffering off;
|
|||
|
|
# }
|
|||
|
|
#
|
|||
|
|
# location /apps {
|
|||
|
|
# proxy_pass http://127.0.0.1:8080;
|
|||
|
|
# proxy_http_version 1.1;
|
|||
|
|
# proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
# proxy_set_header Connection $connection_upgrade;
|
|||
|
|
# proxy_set_header Host $host;
|
|||
|
|
# proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
# proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
# proxy_read_timeout 120s;
|
|||
|
|
# proxy_send_timeout 120s;
|
|||
|
|
# proxy_buffering off;
|
|||
|
|
# }
|
|||
|
|
#
|
|||
|
|
# # 禁止访问的敏感文件
|
|||
|
|
# ... (您现有的安全配置保持不变)
|
|||
|
|
#
|
|||
|
|
# access_log /www/wwwlogs/chat.ay.lc.log;
|
|||
|
|
# error_log /www/wwwlogs/chat.ay.lc.error.log;
|
|||
|
|
# }
|