如何使用 NGINX 部署 NextJS? [英] How to deploy NextJS with NGINX?
问题描述
所以我知道如何在服务器上部署 React 应用程序.
So I know how to deploy a React app on a server.
- npm 运行构建
- 创建一个服务器块并将根目录指向我的 react app 文件夹构建 (root/var/www/xfolder/build;)
- systemctl 重启 nginx
- 运行我的节点服务器(nohup 节点服务器 &&)并完成.
对于 NextJS 不理解这一点,我感到有点愚蠢.我运行 npm run build
I feel kind of dumb for not understanding this with NextJS. I run npm run build
我期待像构建文件夹这样的东西.我尝试将服务器块根设置为/var/www/xfolder/.next 但页面仍然给出 403 禁止.我需要运行 npm run start 吗?我对如何正确部署应用程序感到困惑.我在 DigitalOcean 中使用 Ubuntu、NginX (1gb droplet).
I'm expecting something like a build folder. I've tried setting the server block root to /var/www/xfolder/.next but the page still gives 403 forbidden. And do I need to run npm run start? I'm confuse on how to properly deploy the app. I'm using Ubuntu, NginX (1gb droplet) in DigitalOcean.
推荐答案
我设法让它工作.问题出在我的 Nginx 服务器块上.我只是添加这个块
I managed to make it work. The problem is on my Nginx server block. I just add this block
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;
}
然后运行
npm start
这篇关于如何使用 NGINX 部署 NextJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!