我已在具有Bitnami映像的AWS服务器上部署了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>
答案 0 :(得分:6)
将.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
答案 1 :(得分:1)
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>