Reputation: 4369
I am deploying an Angular 4 application on an EC2 instance. I compiled the application with ng build --prod
and moved the contents of the dist
directory to /var/www/html
. Furthermore, I have started the web service daemon with sudo service httpd start
. The webpage works except that I can only access routes via the main page.
For example I can get to:
http://my-page.com/dashboard
only by first visiting
http://my-page.com
and then clicking on the dashboard button. However, I cannot access this portion of the application directly by navigating to http://my-page.com/dachboard
as was possible in the the angular development environment (Angular CLI server).
I would like to know if this is possible and how to achieve this. The steps that I have taken to try to resolve this are
mod_proxy
by adding RewriteEnging On
and adding ProxyPass * http://my-page.com/
and ProxyPassReverse * http://my-page.com/
to the httpd.conf
fileAllowOverride All
to the httpd.conf
file.htaccess
to allow RewiteEngine.Upvotes: 0
Views: 601
Reputation: 4369
Take a look at this article describing how to deploy an Angular application on Apache. The steps you missed are adding:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
to .htaccess
and adding
<Directory "/var/www/html">
AllowOverride All
</Directory>
to the <VirtualHost *:80>
section of /etc/httpd/conf/httpd.conf
file. That should do the trick.
Upvotes: 1