【发布时间】:2017-05-11 22:04:39
【问题描述】:
我需要为 angular2 配置虚拟主机。我试过关注这篇文章
https://www.packtpub.com/mapt/book/Web+Development/9781783983582/2/ch02lvl1sec15/Configuring+Apache+for+Angular
据此我需要像这样设置虚拟主机
<VirtualHost *:80>
ServerName my-app
DocumentRoot /path/to/app
<Directory /path/to/app>
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html
# to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
谁能告诉我应用程序的路径应该是什么,因为我的应用程序在默认的 Angular 2 端口 4200 上运行。 有没有其他办法呢。
【问题讨论】:
-
您说您的应用程序在使用本地服务器进行开发时在默认的 Angular 2 端口 4200 上运行?当您想在生产服务器上使用它时,您将根据您的构建构建 Angular2 应用程序,如果您使用 angular-cli,您将使用
ng build --prod并将 dist 文件夹的内容上传到您的 apache 服务器文档根目录那个虚拟主机。 -
@JJB 我已经做到了,并且应用程序在 ip:4200 上运行,但我想使用虚拟主机,例如:www.testapp.com 并使用 apache 将其重定向到我的 Angular 应用程序
-
您使用
dist文件夹中的内容,就像您上传该内容并通过 apache 提供该内容的任何其他网站一样,并确保所有 .html 文件都通过 index.html 加载。您所说的是在您不会使用 NodeJS 为您将使用 Apache 服务器的 Angular2 应用程序提供服务的测试环境中运行 Angular 时创建的本地测试服务器。ng serve仅用于服务本地开发服务器,与 Angular 无关。您使用的是 angular-cli 对吗? -
只是为了确定......您的项目实际上是 angular-cli 或某种 webpack??