【问题标题】:Nextjs deployment using Nginx: 403 forbidden on chunks script files使用 Nginx 的 Nextjs 部署:403 forbidden on chunks script files
【发布时间】:2023-02-23 03:52:34
【问题描述】:

我正在使用 Nginx 部署我的 Next 应用程序。
我看到很多资源可以正确配置我的 Nginx,但毕竟 _next/static/chunks 中的 js 文件得到 403 forbidden 错误。

比较迷惑的是,只有chunks目录下的js文件报403错误,其他的没有,比如AkIOTV9_ZRaGvsXBvXd8E目录下的两个js文件(_buildManifest.js, _ssgManifest.js)没有报错,加载了一个200 状态码。

有一些类似的问题,但没有一个对我有帮助。
deploy nextjs with nginx with 403 forbidden
403 Forbidden Nginx

chunks目录及其文件的权限如下所示
1st one 是 js 文件 & 2nd one 是 chunks 目录

这是我的 Nginx 配置

server {

    listen 80;
    server_name shahbazism.ir www.shahbazism.ir;

    gzip on;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/java$
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_min_length 256;

    access_log /var/www/lawyer/logs/nginx-access.log;
    error_log /var/www/lawyer/logs/nginx-error.log;

    root /var/www/lawyer/interface/build;

    location /_next/static/ {
        alias /var/www/lawyer/interface/build/.next/static/;
        expires 365d;
        access_log off;
    }


    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }


}

如果我使用 VPN,403 错误将解决!

【问题讨论】:

    标签: reactjs nginx next.js deployment


    【解决方案1】:

    我遇到了同样的问题并且令人困惑,因为它在某些网络上工作而不是全部。 我在 nginx 中配置了 HTTPS 协议,它得到了修复。

    【讨论】:

      猜你喜欢
      • 2023-01-12
      • 2016-01-31
      • 1970-01-01
      • 2020-06-04
      • 2013-11-02
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 2015-07-07
      相关资源
      最近更新 更多