Vite React.js 应用程序显示正确配置后在 nginx 服务器中未找到 404

问题描述 投票:0回答:1

我将Vite React.js应用程序上传到服务器。我正在使用 nginx 服务器。应用程序运行良好。但是当我转到另一个页面并刷新时,该网站无法正常工作。它显示 404 未找到错误。我在nginx中添加了以下配置,问题仍然存在

 location / {
    try_files $uri $uri/ /index.html;
}

应用程序被配置为子目录,如 www.domain.com/stock/app 当我刷新到给定的网址时,它工作正常,但是当我切换到其他路由(如 www.domain.com/stock)时/app/loginwww.domain.com/stock/app/dashboard 并刷新显示的页面 404 Not Found

我该如何解决这个问题?

reactjs nginx deployment react-router vite
1个回答
0
投票

放入文件夹public:.htaccess

在 .htaccess 中:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule . /index.html [L]
</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.