You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Strapi到DigitalOcean Droplet(Nginx)后无法访问管理面板求助

解决Strapi部署后无法访问管理面板的问题
  • 修正Nginx Server Block的请求转发配置
    当前显示占位页,说明Nginx仍指向默认静态目录,需修改配置将请求转发到Strapi服务:

    1. 编辑你的域名对应的server block文件(路径通常为/etc/nginx/sites-available/[你的域名])
    2. 替换为以下配置(替换your-domain.com为实际域名):
    server {
        listen 80;
        server_name your-domain.com;
    
        location / {
            proxy_pass http://localhost:1337;
            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;
        }
    }
    
    1. 测试Nginx配置语法:sudo nginx -t
    2. 重启Nginx生效:sudo systemctl restart nginx
  • 调整Strapi的生产环境配置
    确保Strapi允许外部访问并绑定正确的域名:

    1. 编辑项目根目录下的config/env/production/server.js(若不存在则编辑config/server.js)
    2. 配置内容如下(替换https://your-domain.com为实际域名,未配置SSL则用http):
    module.exports = ({ env }) => ({
      host: env('HOST', '0.0.0.0'),
      port: env.int('PORT', 1337),
      app: {
        keys: env.array('APP_KEYS'),
      },
      url: env('PUBLIC_URL', 'https://your-domain.com'),
    });
    
    1. 重启pm2中的Strapi进程:pm2 restart [你的Strapi进程名]
  • 验证服务器防火墙规则
    确保HTTP/HTTPS端口对外开放,同时限制Strapi端口仅本地访问:

    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
    sudo ufw allow from 127.0.0.1 to any port 1337
    sudo ufw reload
    
  • 配置SSL(推荐)
    若需通过HTTPS访问,使用Certbot快速配置免费SSL证书:

    sudo apt install certbot python3-certbot-nginx
    sudo certbot --nginx -d your-domain.com
    

    执行后Certbot会自动更新Nginx配置,完成HTTP到HTTPS的重定向。

内容的提问来源于stack exchange,提问作者isoaxe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 20:33:27