【问题标题】:500 internal Server Error on Shared hosting共享主机上的 500 内部服务器错误
【发布时间】:2021-04-04 18:22:13
【问题描述】:

我有一个托管在 www.example.com 的 react 应用程序, 而 REST API 是链接到 www.api.example.com 的后端文件夹内的节点应用程序

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

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

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

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

当我使用以下内容时,我开始遇到不是的 cors preflight 问题

<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 随 react build 的位置。

子域 (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 指向的节点应用程序。

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

【问题讨论】:

  • 您需要查看错误日志以了解 500 错误的详细信息。 www.api.example.com 相对于主域指向哪里?你还有其他.htaccess 文件吗?
  • 我在其他子域中有 .htaccess。我也更新了我的问题@MrWhite

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


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2021-10-18
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 2021-07-29
    • 2022-01-10
    • 1970-01-01
    相关资源
    最近更新 更多