【发布时间】:2018-11-30 00:18:26
【问题描述】:
我确实有一个使用 ReactJS 和 React Router V4 构建的应用程序,我正在尝试将其发布到生产环境中。
在生产中,我有以下配置的 Apache:
$ cat /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName myapp.localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
SetEnv APP_HOME /usr/local/bin/myapp
<Directory "/var/www/html">
AllowOverride All
# Don't rewrite files or subdirectories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
在浏览时,我会这样做:
http://192.168.0.100
它会加载我的着陆页。但从那里我无法访问任何其他网址:
http://192.168.0.100/login
http://192.168.0.100/status
http://192.168.0.100/detail/1
http://192.168.0.100/dashboard
我从 Apache 收到以下错误的所有页面:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /status was not found on this server.</p>
<hr>
<address>Apache/2.4.10 (Debian) Server at 192.168.0.100 Port 80</address>
</body></html>
我很确定我的配置有问题(可能是我的 RewriteCond/RewriteRule),但不知道如何解决它。
【问题讨论】:
标签: reactjs apache debian apache2 react-router-v4