我在ubuntu上运行。我的电脑上运行着 nginx。当我在浏览器中访问我的 IP 地址时,我看到了 nginx 的欢迎页面,但我看不到我的 React 应用程序。我刚刚收到 404 错误,上面写着 nginx。我的应用程序是一个使用 create-react 应用程序构建的 react 应用程序。我使用 npm run build 进行了构建。我在 site-available with 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
当我在浏览器中访问 IP 地址时,显示“无法访问此网站”
每次编辑文件时,我都会重新启动服务器,但错误页面上没有提及 nginx。
systemctl restart nginx
请帮助我。
最佳答案
相信您已经使用浏览器直接加载了index.html来运行...
我相信 nginx 会寻找 .conf 文件。 请尝试将/etc/nginx/sites-available/sdft.nginx 重命名为 sdft.conf 然后请尝试将您的符号链接(symbolic link)设置为
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,并且没有其他服务在竞争。
由于声誉限制,我无法向您提问。
关于reactjs - 我正在运行 nginx,但它不服务于我的 React 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62904721/