
在我的 React 專案中刷新頁面時遇到問題,因為我正在嘗試配置我的 Nginx,因為在我的本地主機中工作正常。
我是 Nginx 的新手,我已經嘗試了 2 個多小時但沒有成功。
情境:
我在 React 中有 2 個項目,使用 React 路由,然後我需要為這兩個項目進行配置,但我正在嘗試先配置一個。
我的第一個項目
/var/www/html/app
和我的第二個項目/var/www/html/dashboard
都運作良好,http://MY_IP/app
並且http://MY_IP/dashboard
我打開文件
/etc/nginx/sites-enabled/default
(我刪除了很多註釋):
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian-html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
只有我改變了:
try_files $uri $uri/ =404; -> try_files $uri $uri/ index.html;
root /var/www/html; -> root /var/www/html/app;
並在控制台之後:sudo systemctl restart nginx
問題:
當我進行更改時,沒有任何反應,頁面http://MY_IP/app
是空白的。
我嘗試了很多變體,但是當我刷新時http://MY_IP/app/sale
繼續出現錯誤並且路線不起作用。
我做錯了什麼?
筆記:
- 我的 nginx 在 EC2(aws) 中
謝謝。