![](/img/trans.png)
[英]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.