apache2 - Angular2 部署
问题描述
我已经构建了一个 angular2 应用程序并将其构建用于生产。我根据角度部署文档创建了 .htaccess 文件。将角度“dist”文件夹放在 apache2 根目录中后,访问项目的任何页面都没有问题。
但是,一旦我将“dist”文件夹放在 VirtualBox apache2 根目录中并使用来宾 ip (VirtualBox) 访问它,除了登录的 '/' 之外的所有 url 都会得到 '/ url not found on this server' 。
解决方案
将其粘贴到 .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 后,网站运行正常。
推荐阅读
- python - CPython 的解释器如何知道打印最后一个表达式的结果?
- css - 复选框不显示
- python - 如何将多个数字分配给一个单词中的多个字母?
- php - php - 用 HTML 替换模板代码
- python-3.x - Python - 为 Graphviz 导出最终的随机森林树
- java - 如何并行处理文件的行?
- ibm-cloud - Watson Assistant - 从选定区域加载组织时发生错误
- java - 使用 Java SDK 列出 Amazon S3 中的所有对象
- angular - Angular2:用于路由的共享组件
- sql - 选择符合 PostgreSQL 条件的最新连续记录