2016-02-28 103 views
1

我已經在帶有Bitnami映像的AWS服務器上部署了Angular2應用程序。 該應用程序由Apache(在端口8080上配置一個虛擬主機)提供服務,並且工作正常,只要我從index.html開始。如果我想訪問另一個頁面(已在RouteConfig中配置),則會出現404 not found錯誤。 這裏是虛擬服務器的配置:Apache與Angular2 - 404未找到

Listen 8080 
<VirtualHost _default_:8080> 
    DocumentRoot "/opt/bitnami/apps/MyApp" 
<Directory "/opt/bitnami/apps/MyApp"> 
Options All 
Require all granted 
</Directory> 
</VirtualHost> 

回答

4

添加.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 

它提供index.html的會導致404所有的請求......

+0

感謝,它的工作原理。我只需在'' – Picci

+0

部分指定'AllowOverride All',這應該被認爲是正確的答案。 – RenanSS

0

ServerName angular2ssipl 


    ServerAdmin [email protected] 
    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> 

+0

我希望它的幫助 –