共享主机上的 500 内部服务器错误

500 internal Server Error on Shared hosting

我在 www.example.com 上托管了一个 React 应用程序, 而 REST API 是链接到 www.api.example.com

的后端文件夹中的节点应用程序

但是,只要我的反应构建中的 .htaccess 文件中有内容,我的休息 API 就会显示 500 个内部服务器错误。 这个 .htaccess 是我的 React 应用程序渲染良好所必需的。

我尝试了几种选择,但似乎有 none 适合我的用例。

这是我的 .htaccess 文件,位于我的 Cpanelpublic_html 文件夹中

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.html [QSA,L]

当我使用下面的内容时,我开始遇到 cors 预检问题,这不是

<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>

我的日志文件显示了这个

App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_exec_wrapper/end_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.1)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_wrapper_preparation/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.104)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_wrapper_preparation/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.134)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_wrapper_preparation/end_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.134)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_app_load_or_exec/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.135)
App 5580 output: [!] Starting Wig Tools API server...
App 5580 output: [✔] Application middlewares connected
App 5580 output: [✔] Application Routes connected
App 5580 output: [!] Checking For Super admin...
App 5580 output: (node:5580) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
App 5580 output: (Use `node --trace-warnings ...` to show where the warning was created)
App 5580 output: (node:5580) [SEQUELIZE0006] DeprecationWarning: This database engine version is not supported, please update your database server. More information https://github.com/sequelize/sequelize/blob/main/ENGINE.md
App 5580 output: [✔] Super admin already initialized
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_app_load_or_exec/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.108)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_app_load_or_exec/end_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.108)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_listen/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.108)
App 5580 output: [✔] Listening on PORT: 30510
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_listen/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.111)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_listen/end_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.112)
App 5580 output: [0mGET /products/best-sold [32m200[0m 8.764 ms - 58[0m
App 5580 output: [0mGET /categories [32m200[0m 4.286 ms - 3784[0m

根 public_html 是主域指向 (www.example.com) 的地方,这是我的 htaccess 随反应构建而来的地方。

默认情况下,子域 (api.example.com) 在 public_html 中有一个文件夹。

api 子域默认有这个 (.htaccess)

# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/wigtool1/public_html/backend"
PassengerBaseURI "/"
PassengerNodejs "/home/wigtool1/nodevenv/public_html/backend/14/bin/node"
PassengerAppType node
PassengerStartupFile /home/wigtool1/public_html/backend/src/index.js
PassengerAppLogFile "/home/wigtool1/logs/api.log"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END

而后端是一个文件夹,其中包含 api.example.com 指向的节点应用程序。

如何在不冲突的情况下解决这个问题

我通过在我的 React 应用程序中使用 hashRouter 解决了这个问题。而不是使用 BrowserRouter

import { HashRouter as Router, Route, Switch } from "react-router-dom";

此外,这不需要 htaccess 现在就可以工作,因为我的服务器不是 ngix