首页 > 解决方案 > Angular2 部署

问题描述

我已经构建了一个 angular2 应用程序并将其构建用于生产。我根据角度部署文档创建了 .htaccess 文件。将角度“dist”文件夹放在 apache2 根目录中后,访问项目的任何页面都没有问题。

但是,一旦我将“dist”文件夹放在 VirtualBox apache2 根目录中并使用来宾 ip (VirtualBox) 访问它,除了登录的 '/' 之外的所有 url 都会得到 '/ url not found on this server' 管理页面

标签: apache2virtualboxangular2-routing

解决方案


将其粘贴到 .htaccess 中

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

并检查 /etc/apache2/sites-enabled/000-default.conf文件。

<Directory "/var/www/html/dist">
 AllowOverride All
</Directory>

添加此内容并重新启动 apache 后,网站运行正常。


推荐阅读