【发布时间】:2017-08-19 16:01:54
【问题描述】:
我想在 Apache 服务器上部署 Angular 2 应用程序。我已经阅读了各种指南,例如 this 和 this,但它们都不起作用。我在服务器上安装了npm 和ng。
简而言之,这就是我所做的:
- 在我的服务器上克隆了完整的项目存储库。
- 使用
npm install安装依赖项。 - 使用了
ng build --prod命令并创建了一个dist目录。 - 已将
apache根目录更改为/var/www/html/dist目录。 - 启用
mod_rewrite,重新启动apache,并将此.htaccess添加到我的dist目录中。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
但只有我的主页 domain.com 有效,其他页面如 domain.com/login、domain.com/register 等会抛出 404 错误。即使domain.com/index.html/login 也不起作用。
该应用程序在我使用ng serve 开发它的本地系统上运行良好。我错过了什么?
【问题讨论】:
标签: apache .htaccess angular digital-ocean