如何为angular 2配置apache [英] How to configure apache for angular 2

查看:33
本文介绍了如何为angular 2配置apache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 angular2 配置虚拟主机.我试过按照这篇文章

I need to configure virtual host for angular2. I have tried following this article

https://www.packtpub.com/mapt/book/Web+Development/9781783983582/2/ch02lvl1sec15/Configuring+Apache+for+Angular

因此我需要像这样设置虚拟主机

According to this i need to setup virtual host like this

<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>

谁能告诉我应用程序的路径应该是什么,因为我的应用程序在 4200 的默认 angular 2 端口上运行.有没有其他方法可以做到这一点.

Can anyone tell me what should be the path to app as my app is running on default angular 2 port that is 4200. Is there any other way to do it.

推荐答案

angular-cli build

在您的本地开发环境中,在您的项目根目录中运行 ng build --prod.

On your local development environment run ng build --prod in your project root.

这将创建一个名为 dist 的文件夹,您希望将 dist 中的所有文件和文件夹放置到您服务器上的 Apache 根目录中.

This will create a folder called dist, you want to place all the files and folders from within dist to your Apache root directory on your server.

设置 apache 以提供到 index.html 的路由.您可以使用两种方法,编辑虚拟主机或使用网站根目录中的 .htaccess.

Setup apache to serve routes to index.html. You have two methods you can use, either edit your virtual host or use .htaccess in your website root directory.

选项 1:虚拟主机

<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>

<小时>

选项 2:.htaccess

<IfModule mod_rewrite.c>
    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]
</IfModule>

这篇关于如何为angular 2配置apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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