将Angular 2部署到Apache服务器 [英] Deploy Angular 2 to Apache Server

查看:374
本文介绍了将Angular 2部署到Apache服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Apache服务器上部署Angular 2应用程序。我已经阅读了各种指南,例如,但是它们都不起作用。我在服务器上安装了 npm ng

I want to deploy an Angular 2 application on an Apache server. I've read various guides like this and this but none of them is working. I have npm and ng installed on server.

简而言之,这就是我的工作:

In nutshell, here's what i did:


  1. 服务器上已克隆的完整项目存储库。

  2. 已安装依赖使用 npm install

  3. 使用 ng build --prod 命令并它创建了一个 dist 目录。

  4. apache 的根目录更改为 / var / www / html / dist 目录。

  5. 启用 mod_rewrite ,重新启动 apache 并将此 .htaccess 添加到我的 dist 目录中。

  1. Cloned complete project repository on my server.
  2. Installed dependencies using npm install.
  3. Used ng build --prod command and it created a dist directory.
  4. Changed apache root to /var/www/html/dist directory.
  5. Enabled mod_rewrite, restarted apache and added this .htaccess in my dist directory.

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

但只有我的主页域.com 正常工作,其他页面如 domain.com/login domain.com/register 等。抛出404错误。甚至 domain.com/index.html/login 也不起作用。

But only my home page domain.com works, other pages like domain.com/login, domain.com/register etc. throw 404 error. Even domain.com/index.html/login doesn't work.

该应用程序在我的本地计算机上运行良好我正在使用 ng服务开发它的系统。我缺少什么?

The application works fine on my local system where I'm developing it using ng serve. What am i missing?

推荐答案

似乎我的 / etc / apache2 / sites中缺少此功能-enabled / 000-default.conf 文件。添加并重新启动 apache 后,网站运行正常。

It appears i was missing this in my /etc/apache2/sites-enabled/000-default.conf file. After adding this and restarting apache, website runs fine.

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

这篇关于将Angular 2部署到Apache服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆