我需要为angular2配置虚拟主机.我试过这篇文章
https://www.packtpub.com/mapt/book/Web+Development/9781783983582/2/ch02lvl1sec15/Configuring+Apache+for+Angular
Run Code Online (Sandbox Code Playgroud)
根据这个我需要像这样设置虚拟主机
<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>
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我应用程序的路径应该是什么,因为我的应用程序在4200的默认角度2端口上运行.还有其他方法可以做到这一点.
J J*_*J B 17
angular-cli build
在ng build --prod项目根目录中运行的本地开发环境中.
这将创建一个名为的文件夹dist,您希望将所有文件和文件夹dist放在服务器上的Apache根目录中.
设置apache以提供到index.html的路由.您可以使用两种方法,编辑虚拟主机或在网站根目录中使用.htaccess.
选项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>
Run Code Online (Sandbox Code Playgroud)
选项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>
Run Code Online (Sandbox Code Playgroud)