[英]“pm2 serve build PORT” echoes 404 not found
I've done this tutorial, 我已经完成了本教程,
https://reactjs.org/tutorial/tutorial.html https://reactjs.org/tutorial/tutorial.html
Then uploaded it to production server, running on ubuntu nginx with SSL. 然后将其上传到生产服务器,并在具有SSL的ubuntu nginx上运行。 Ran
npm run build
, created the build files and served static files with serve module serve -s -p 8083 build
. 用
npm run build
,创建了构建文件,并使用serve模块 serve -s -p 8083 build
服务了静态文件。 It runs OK on port 8083. 它在端口8083上运行正常。
But when I try to add it as a pm2 service pm2 serve ./build/ 8083
I get a 404 not found (when it's not running the error is 502 Bad Gateway) 但是,当我尝试将其添加为PM2服务
pm2 serve ./build/ 8083
我得到找不到404(当它没有运行错误是502错误网关)
I tried several ways, with pm2 serve ./ 8083
, pm2 serve ./public/ 8083
, etc. 我尝试了几种方法,其中
pm2 serve ./ 8083
, pm2 serve ./public/ 8083
等。
Nginx config: Nginx配置:
location ~* /.(js|jpg|png|css)$ {
access_log off;
expires max;
}
location = /react-game {
root /var/www/test.com/html/react-game/build;
proxy_pass http://localhost:8083;
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;
autoindex off;
}
Any ideas how to replicate serve -s -p 8083 build
with pm2? 有什么想法如何使用pm2复制
serve -s -p 8083 build
吗?
Thanks! 谢谢!
I think the main issue is serve
is meant to serve static files and pm2
is meant to persistently run a script. 我认为主要问题是
serve
是为静态文件提供服务,而pm2
是要持久运行脚本。 Here is an article about serving react with pm2: 这是有关与pm2互动的文章:
https://ygamretuta.xyz/deploy-create-react-app-with-pm2-16beb90ce52 https://ygamretuta.xyz/deploy-create-react-app-with-pm2-16beb90ce52
But is there a reason you don't want to just make nginx listen on port 8083 and serve the build files statically by itself? 但是,您是否有理由不想让Nginx在端口8083上监听并自己静态地提供构建文件? Or is there a reason you're not serving the build files on port 80?
还是有一个原因您不在端口80上提供构建文件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.