nginx - 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
命令,但我得到了相同的结果。
希望您能够帮助我。
解决方案
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;
}
}
推荐阅读
- java - 如何设置 JAVA SSL 连接的持续时间
- angular - mat-paginator 不适用于 [隐藏]
- c# - 如何在处理流之间保存值?
- reactjs - 环回Rest API内的console.log
- postgresql - Postgres json查询
- polymer - 将活动类添加到路由器链接 - LitElement
- node.js - 如何在 Sequelize.js 中查询 Group by 和 MAX(id)
- javascript - 在node js中将Json文件内容集成到Sqlite中
- java - Coverity 工具抛出:在空对象 java.lang.ClassLoader.getSystemClassLoader() 上调用方法
- php - '/usr/sbin/apache2 -k start' 进程太多