所以我知道如何在服务器上部署 React 应用程序。
- npm 运行构建
- 创建一个服务器块并将根指向我的反应应用程序文件夹构建(根 /var/www/xfolder/build;)
- systemctl 重新启动 nginx
- 运行我的节点服务器(nohup节点服务器&&)并完成。
I feel kind of dumb for not understanding this with NextJS. I run npm run build
![enter image description here](https://i.stack.imgur.com/g5vuh.png)
我期待类似构建文件夹的东西。我尝试将服务器块根设置为/var/www/xfolder/.next但页面仍然给出403禁止。我需要运行 npm run start 吗?我对如何正确部署应用程序感到困惑。我在 DigitalOcean 中使用 Ubuntu、NginX(1gb Droplet)。
检查一下:https://gist.github.com/iam-hussain/2ecdb934a7362e979e3aa5a92b181153 https://gist.github.com/iam-hussain/2ecdb934a7362e979e3aa5a92b181153
HTTP/HTTPS 参考:https://gist.github.com/iam-hussain/2ecdb934a7362e979e3aa5a92b181153 https://gist.github.com/iam-hussain/2ecdb934a7362e979e3aa5a92b181153
在端口 8080 启动 PM2 nextJS 服务:
cd PROJECT_DIRECTORY
pm2 start "npm run start -- -p 8080" --name contractverifier
配置 Nginx:
将此文件替换为以下代码/etc/nginx/sites-available/default
server {
server_name www.DOMAINNAME.com DOMAINNAME.com;
index index.html index.htm;
root /home/ubuntu/PROJECT_FOLDER; #Make sure your using the full path
# Serve any static assets with NGINX
location /_next/static {
alias /home/ubuntu/PROJECT_FOLDER/.next/static;
add_header Cache-Control "public, max-age=3600, immutable";
}
location / {
try_files $uri.html $uri/index.html # only serve html files from this dir
@public
@nextjs;
add_header Cache-Control "public, max-age=3600";
}
location @public {
add_header Cache-Control "public, max-age=3600";
}
location @nextjs {
# reverse proxy for next server
proxy_pass http://localhost:8080; #Don't forget to update your port number
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;
}
listen 80 default_server;
listen [::]:80;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)