我已经使用Bitnami镜像在亚马逊网络服务服务器上部署了一个Angular2应用程序。这个应用程序由Apache提供服务(在端口8080上配置了一个虚拟主机),只要我从index.html启动,它就能正常工作。如果我想访问一个不同的页面(已经在RouteConfig中配置),我会得到一个404 not found错误。下面是虚拟服务器的配置:
Listen 8080
<VirtualHost _default_:8080>
DocumentRoot "/opt/bitnami/apps/MyApp"
<Directory "/opt/bitnami/apps/MyApp">
Options All
Require all granted
</Directory>
</VirtualHost>发布于 2016-02-29 16:15:06
将.htaccess文件添加到根文件夹。我使用的是:
# BEGIN ServeStatic
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# END ServeStatic 它为所有可能导致404...的请求提供index.html服务
发布于 2016-09-27 13:26:28
ServerName angular2ssipl
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/SSIPL-Angular
# 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
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
<Directory /var/www/html/SSIPL-Angular/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
Require all granted
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
</Directory>
发布于 2022-02-06 04:42:41
这就是我的工作(感谢@Ankur Loriya和其他许多人让我做到了这一点)……
转到包含index.html文件的目录。
sudo nano .htaccess将以下内容添加到文件中:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html退出Nano (Control+X)并保存更改(Y)。
cd /etc/apache2
sudo nano apache2.conf在文件的底部,有一系列<Directory>标记。找到下面这样写的:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>...and将AllowOverride None更改为AllowOverride All
退出Nano (Control+X)并保存更改(Y)。
我不确定是否需要以下命令,但我做到了:
sudo a2enmod rewrite 最后,重新启动Apache:
sudo service apache2 restart这就完成了。
https://stackoverflow.com/questions/35689696
复制相似问题