Node.js 在回调时使用Express和Apache-enoint
我正在尝试使用Express在Apache服务器上运行React webapp。 应用程序正在使用hashHistory在前端使用路由。 每件事都会在当地产生魅力。 在我的生产服务器上,这一切似乎都有点问题,我的身份验证库Auth0试图回调一个前端路由,该路由抛出404,并出现以下错误:Node.js 在回调时使用Express和Apache-enoint,node.js,apache,reactjs,express,auth0,Node.js,Apache,Reactjs,Express,Auth0,我正在尝试使用Express在Apache服务器上运行React webapp。 应用程序正在使用hashHistory在前端使用路由。 每件事都会在当地产生魅力。 在我的生产服务器上,这一切似乎都有点问题,我的身份验证库Auth0试图回调一个前端路由,该路由抛出404,并出现以下错误: Error: ENOENT: no such file or directory, stat '/dist/index.html' at Error (native) 我的虚拟主机条目如下所示: &l
Error: ENOENT: no such file or directory, stat '/dist/index.html'
at Error (native)
我的虚拟主机条目如下所示:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin admin@domain.com
ServerName domain.com
DocumentRoot /var/www/html/folder
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /*>
ProxyPass http://127.0.0.1:9000
ProxyPassReverse http://127.0.0.1:9000
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
这是我的Express服务器:
var express = require('express')
var app = express()
var path = require('path');
app.use(express.static('dist'))
app.get('*', function(req, res) {
res.sendFile(path.resolve(__dirname, 'dist/index.html'));
});
app.listen(9000, function () {
console.log('Example app listening on port 9000!')
})
当我启动应用程序时,会调用Auth0 API尝试对用户进行身份验证,但由于上面的错误消息而失败
我应该补充一点,当/login不可用时,//login确实可以帮助您实现目标。不知道为什么或者它意味着什么
不知道我做错了什么。有人能帮忙吗?多亏了@pierre-r-a的建议才解决了这个问题 我读了这篇文章,这是一个很好的指南,可以指导我的工作: 我只是将它添加到虚拟主机的配置文件中,现在一切都很顺利
<Location /login>
ProxyPass http://127.0.0.1:9000
ProxyPassReverse http://127.0.0.1:9000
</Location>
你能告诉我们完整的目录结构和你试图访问的URL/地址吗?是的,我已经更新了上面的问题。谢谢你是作为前端的吗?我用React,用hashHistory管理路线。该死,我从来没有玩过React,但我怀疑你的麻烦就在那里。去看看这里:
<Location /login>
ProxyPass http://127.0.0.1:9000
ProxyPassReverse http://127.0.0.1:9000
</Location>