Skip to content

Nginx 部署

快速配置

只需 2 步:

  1. 站点根目录指向 public/ 文件夹
  2. 添加以下伪静态配置

伪静态配置

nginx
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
    expires 30d;
    try_files $uri =404;
}

# API 路由转发
location /api/ {
    try_files $uri $uri/ /index.php?s=$uri&$args;
}

# 文档站(如已部署帮助文档)
location /docs/ {
    try_files $uri $uri/ /docs/index.html;
}

# PHP 处理
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTP_AUTHORIZATION $http_authorization;
    include fastcgi_params;
}

# 前端 SPA 路由
location / {
    try_files $uri $uri/ /index.html;
}

# 安全:禁止访问敏感文件
location ~ /\.(ht|git|env) {
    deny all;
}

必须配置

nginx
fastcgi_param HTTP_AUTHORIZATION $http_authorization;

否则登录后会提示"未授权",因为 JWT Token 无法传递到 PHP。

常见问题

问题原因解决
页面 404伪静态未生效检查配置并重启 Nginx
登录后"未授权"Authorization 未传递添加 HTTP_AUTHORIZATION 配置
API 404路由未转发检查 location /api/ 配置
静态资源 404根目录错误确认指向 public/ 文件夹

下一步

GEO优化平台 - AI内容创作与优化