[使用rhel7在Apache服务器上托管React App,但我的Javascript似乎没有执行

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

我正在尝试在Apache服务器上托管React应用,并且遇到了典型的空白白纸问题。我已经审查了关于该主题的所有帖子,但它们似乎与我所遇到的问题不同。

为了简单起见,我从构建中删除了我的css文件,以防万一它们使事情进一步复杂化。

我在package.json中将主页设置为'./',然后在该应用上运行npm run build。

我将文件复制到/ var / www / html中的apache根目录中(为简单起见,我将它们从build文件夹中删除)

我修改了html以将javascript调用设置为如下所示

<script type='text/jsx' src='./var/www/html/static/foo.js'>

我已在.htaccess file中添加了每个链接说明中与index.html相同的级别。我已经跑过

restorecon -r /var/www/html'

下一级以确保重新建立正确的连接。

我已经用DocumentRoot的'/ var / www / html'更新了.config文件,并将DirectoryIndex保留为index.html。我还在上面发布的指南中的链接中添加了一些额外的内容(应该是多余的)

<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride All

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

#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
ServerName localhost

我添加的唯一相关的“新”东西是使服务器成为本地主机。 Reddit上有人在我发现的另一篇文章中建议了它。

[检查控制台时,我看到一个对http://localhost/的请求,该请求从index.js检索我的html。但是我似乎并没有在另一端加载或执行我的任何JavaScript,因此没有加载。

有人对我在做什么错有任何想法吗?我什至不知道是什么原因导致此问题。

reactjs apache rhel7
1个回答
0
投票

我终于让当当的东西起作用了!我写这本书是为了我自己的教育,就像其他人一样。

我将应用程序的首页设置为'。并从配置文件中删除了服务器名组件。我修改了html,以使路径不再显示为“ ./foo/bar”,而是显示为“ / foo / bar”。然后,我将html标记的脚本组件移到主体外部(在主体下方),一切正常。

我不知道为什么这么麻烦—我只是以为React可以像Apache之类的东西开箱即用,但是终于完成了!

© www.soinside.com 2019 - 2024. All rights reserved.