ubuntu - NEXT-AUTH -/api/auth/signin 上的 500 内部服务器错误,无法访问实时站点上的登录页面

标签 ubuntu nginx next.js next-auth

我一直在寻找,但我没有找到任何与我的案子相关的东西。
我在 next.js 应用程序上使用 nextauth 进行简单登录以管理网站上的内容。
evet 因为我在 digital ocean 上的 ubuntu 20.04 液滴中配置了 nginx,当我尝试访问/api/auth/signin 页面时,我收到 500 内部服务器错误
这是我尝试访问登录页面后的下一个身份验证日志 - 为了清楚起见,出于隐私原因,EXAMPLE 是一个占位符:

[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error invalid json response body at https://EXAMPLE.com/api/auth/session reason: Unexpected token I in JSON at position 0 { error:
   { message:
      'invalid json response body at https://EXAMPLE.com/api/auth/session reason: Unexpected token I in JSON at position 0',
     stack:
      'FetchError: invalid json response body at https://EXAMPLE.com/api/auth/session reason: Unexpected token I in JSON at position 0\n    at /var/www/EXAMPLE.com/node_modules/node-fetch/lib/index.js:272:32\n    at process._tickCallback (internal/process/next_tick.js:68:7)',
     name: 'FetchError' },
  path: 'session',
  header:
   { 'x-real-ip': '5.28.71.45',
     'x-forwarded-for': '5.28.71.45',
     'x-nginx-proxy': 'true',
     host: 'EXAMPLE.com',
     connection: 'close',
     'sec-ch-ua':
      '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
     'sec-ch-ua-mobile': '?0',
     'sec-ch-ua-platform': '"Windows"',
     'upgrade-insecure-requests': '1',
     'user-agent':
      'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
     accept:
      'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
     purpose: 'prefetch',
     'sec-fetch-site': 'none',
     'sec-fetch-mode': 'navigate',
     'sec-fetch-user': '?1',
     'sec-fetch-dest': 'document',
     'accept-encoding': 'gzip, deflate, br',
     'accept-language': 'en-US,en;q=0.9,de;q=0.8,he;q=0.7' },
  message:
   'invalid json response body at https://EXAMPLE.com/api/auth/session reason: Unexpected token I in JSON at position 0' }
/var/www/EXAMPLE.com/node_modules/openid-client/lib/issuer.js:32
  #metadata;
  ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/var/www/EXAMPLE.com/node_modules/openid-client/lib/index.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
我猜测位置 0 的意外 I 可能是内部服务器错误中的 I
我很确定它与 nginx 配置有关,因为当我第一次设置我的项目时,没有 ngnix,一切正常 - 我能够毫无问题地访问/api/auth/sigin 页面。当谈到 ngnix 时,我完全是个菜鸟,所以我很可能错过了我需要做的事情。
在/etc/nginx/sites-enabled/default 中:
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        return 301 https://$host$request_uri;
}

server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name EXAMPLE.com;

    # Use the Let’s Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/EXAMPLE.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/EXAMPLE.com/privkey.pem;

    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:8080/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }
}
任何帮助或提示将不胜感激,甚至是对 ngnix 替代方案的建议,该替代方案将与 next-auth 轻松工作(或者只是摆脱 url 旁边的“不安全”感叹号,因为这是我使用的唯一原因ngnix。)

最佳答案

尝试将 NodeJs 的版本更新为较新的版本,可以是这样。

关于ubuntu - NEXT-AUTH -/api/auth/signin 上的 500 内部服务器错误,无法访问实时站点上的登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70853859/

相关文章:

linux - 在 bash 脚本中打开 pdf 文件的命令

linux - register_netdevice_notifier回调未提供有效的net_device

Nginx 反向代理多个后端

typescript - 无法生成 Jest 覆盖率报告

ubuntu - COBOL 顺序文件 I/O

php - 将 php 容器与 mongodb 容器链接

php - 在 nginx 位置重写前缀 url

nginx - nginx 中的位置和文档路径

typescript - 带有 NextJS 调试的 VSCode Typescript

angular - 找不到模块 : Error: Can't resolve 'net' in 'node_modules/stompjs/lib'