首页 > 解决方案 > Nuxt 部署中的“无法访问此页面”

问题描述

我正在尝试使用 pm2 在 Nginx 上的 Digital Ocean 上部署 Nuxt 应用程序。当我转到 droplet IP 时,我可以看到 Nginx 欢迎页面,但是当我尝试转到 Nuxt 应用程序的 IP:PORT 时,它说:

This site can’t be reached
167.xx.xxx.xxx refused to connect.
Try:

Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED

我已将其添加到站点可用/默认文件中:

server {
   server_name domain.com;
    location / {
        proxy_pass http://localhost:7200;
       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;
   }
}

在此之后,我检查了 nginx 状态并重新启动它。

另外,我在 pm2 上添加了服务pm2 start --name="webapp" npm -- start,我可以看到它运行正常。

即使我尝试过直接运行npm run start命令,但我得到了相同的结果。

希望您能够帮助我。

标签: nginxnuxt.jsdigital-oceanpm2

解决方案


  server {
    listen       80;
    server_name  localhost;
    location / {
      root   /app;
      index  index.html;
      try_files $uri $uri/ /index.html;
      proxy_redirect off;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
  }

推荐阅读