简体   繁体   English

如何为角度2配置apache

[英]How to configure apache for angular 2

I need to configure virtual host for angular2. 我需要为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>

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. 任何人都可以告诉我应用程序的路径应该是什么,因为我的应用程序在4200的默认角度2端口上运行。还有其他方法可以做到这一点。

angular-cli build angular-cli build

On your local development environment run ng build --prod in your project root. 在本地开发环境中,在项目根目录中运行ng build --prod

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. 这将创建一个文件夹,名为dist ,要从内将所有的文件和文件夹dist到Apache的根目录服务器上。

Setup apache to serve routes to index.html. 设置apache以提供到index.html的路由。 You have two methods you can use, either edit your virtual host or use .htaccess in your website root directory. 您可以使用两种方法,编辑虚拟主机或在网站根目录中使用.htaccess。


Option 1: Virtual Host 选项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>

Option 2: .htaccess 选项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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM