【发布时间】:2022-04-05 21:26:05
【问题描述】:
Next.js 版本 10.0.6 - 节点版本 12.18.4 - Linux 18.04
在我的服务器上,我试图将 URL 直接更改为 about 页面(通过键入 URL - 而不是单击链接),但它给了我一个 502 错误网关。任何复制粘贴到 URL 都不起作用。当我点击“关于”链接时,只有在我的导航栏中才能导航到关于页面。
例子:
www.example.com/about
在我的 PC 上,开发模式下的操作运行良好。问题出在我的服务器上。
我的部署步骤:
package.json 文件:
"scripts": {
"dev": "next dev",
"build": "next build && next export",
"start": "next start"
},
npm run build
我从“out”文件夹中取出所有文件并将它们放在我的服务器上。
nginx 配置文件:
server {
listen myip:80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
location / {
proxy_pass http://localhost: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;
}
location ~ /.well-known {
allow all;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /vstats/ {
alias /home/admin/web/example.com/stats/;
include /home/admin/conf/web/example.com.auth*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/admin/conf/web/nginx.example.com.conf*;
}
我重启Nginx的服务,启动pm2。
sudo service nginx restart
pm2 start npm --name "next" -- start
我做错了什么?我的配置正确吗?
如果您需要任何其他信息,请随时问我。
【问题讨论】:
-
在 URL 末尾添加
.html会使页面正常工作吗? -
不,它不起作用