2016-02-28 4 views
1

Я развернул приложение Angular2 на сервере AWS с изображением Bitnami. Приложение обслуживается 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

спасибо, это работает. Мне нужно было только указать 'AllowOverride All' в разделе' ' – Picci

+0

, это должно считаться правильным ответом. – 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

Я надеюсь, что это поможет –

Смежные вопросы