[英]When running "serve -s build" to serve my React build folder locally, no content renders
[英]I have nginx running but it doesn't serve my react build
我在 ubuntu 上运行。 我有 nginx 在我的电脑上运行。 当我 go 到浏览器中的 ip 地址时,我得到了 nginx 的欢迎页面,但我看不到我的反应应用程序。 我只是收到一个 404 错误,上面写着 nginx。 我的应用程序是使用 create-react 应用程序构建的反应应用程序。 我使用 npm 运行构建进行构建。 我在站点可用 nano 中创建了一个站点。 看起来像
server {
server_name 192.168.43.177;
root home/a/Documents/d/dapp1/mainDapp/client/build/;
index index.html;
location / {
try_files $uri /index.html =404;
}
}
起初我跑
sudo ln -s /etc/nginx/sites-available/sdft /etc/nginx/sites-enabled/sdft
这会在浏览器中显示 404 错误页面,上面写着 nginx。 然后我运行了这个命令
sudo ln -s /etc/nginx/sites-available/sdft.nginx /etc/nginx/sites-enabled/sdft.nginx
当我在浏览器中将 go 转到 ip 地址时,会显示“无法访问此站点”
每次编辑文件时,我都会重新启动服务器,但错误页面上没有提及 nginx。
systemctl restart nginx
请帮我。
相信您已经使用浏览器直接加载了 index.html...
我相信 nginx 会寻找 .conf 文件。 请尝试将您的 /etc/nginx/sites-available/sdft.nginx 重命名为 sdft.conf 然后请尝试将您的符号链接设置为
ln -s /etc/nginx/sites-available/sdft.conf /etc/nginx/sites-enabled/sdft.conf
如果您的问题仍未解决,请尝试
server {
server_name 192.168.43.177;
root home/a/Documents/d/dapp1/mainDapp/client/build/;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
注意从 index.html 到 $uri/ 位置的变化。 还请确认您的系统正在侦听端口 80,并且没有其他服务在竞争。
由于声誉限制,我无法向您提问。
首先检查 nginx 的所有配置是否通过:
sudo nginx -t
没事吧?
sudo ln -s /etc/nginx/sites-available/**sdft** /etc/nginx/sites-enabled/**sdft**
这些文件名必须匹配。
并尝试添加listen 80;
,以便它知道要监听的端口。
server {
listen 80; # add this
server_name 192.168.43.177;
root home/a/Documents/d/dapp1/mainDapp/client/build/;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.