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

时间:2021-04-04 18:22:13

标签: node.js reactjs .htaccess subdomain shared-hosting

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

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

但是,只要我的 react 构建的 .htaccess 文件中有内容,我的 rest API 就会显示 500 个内部服务器错误。 我的 React 应用需要这个 .htaccess 才能很好地呈现。

我尝试了几个选项,但似乎没有一个适合我的用例。

这是我的 Cpanel 的 public_html 文件夹中的 .htaccess 文件

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) 的地方,这是我在 react 构建中获得 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 指向的节点应用程序。

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

1 个答案:

答案 0 :(得分:1)

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

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

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