我正在使用wampserver作为本地服务器作为我的角应用程序。
我使用ng build --prod --aot命令构建了我的应用程序。然后,我将dist文件夹放入一个名为angular.local的虚拟主机中,在httpd-vhosts.conf配置文件中有以下脚本:
<VirtualHost *:80>
ServerName angular
DocumentRoot "c:/wamp64/www/angular"
<Directory "c:/wamp64/www/angular/">
#Options +Indexes +Includes +FollowSymLinks +MultiViews
#AllowOverride All
#Require local
Allow from 127.0.0.1
Allow from 192.168.0.140
Require all granted
</Directory>
</VirtualHost>其中192.168.0.140是用户笔记本电脑的网络IP地址,我们将从其中访问应用程序。
在servers system32主机文件中,我添加了以下行:
192.168.0.109 angular.local
::1 angular.local其中192.168.0.109是服务器的IP地址。
当用户尝试使用链接访问应用程序时:
http://192.168.0.109/angular/
我们可以在google选项卡标题上看到应用程序的标题,但是控制台上有3个错误:

在此运行时,找不到样式和主java脚本文件。
我在服务器角文件夹上检查了它们,它们确实存在。
我所做的和提到的在这个链接中一样。
我在项目文件夹中有.htaccess。
我可以使用http://192.168.0.109/访问本地主页。
我试过使用以下链接,但没有成功:
http://angular.local/
有什么想法吗?
发布于 2018-10-18 09:23:08
通过使用APache 2.2语法和Apache2.4语法,您混淆了APache。所以,坚持使用Apache2.4语法。
另外,你ServerName应该是ServerName angular.local
<VirtualHost *:80>
ServerName angular.local
DocumentRoot "c:/wamp64/www/angular"
<Directory "c:/wamp64/www/angular/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
Require ip 192.168.0.140
</Directory>
</VirtualHost>和另一个用于dev.local的VH,因此假设它位于一个名为dev的文件夹中,在www下。
<VirtualHost *:80>
ServerName dev.local
DocumentRoot "c:/wamp64/www/dev"
<Directory "c:/wamp64/www/dev/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
Require ip 192.168.0.140
</Directory>
</VirtualHost>如果您想要允许从本地网络中的任何ip,那么我们而不是上面的
Require ip 192.168.0假设WAMPServer运行在ip 192.168.0.10上,您还必须将域名添加到其他pc上的主机文件中。
192.168.0.10 angular.local
192.168.0.10 dev.local发布于 2018-10-18 09:29:56
使用以下代码:
<VirtualHost *:80>
ServerName servername.com
DocumentRoot path/to/dist
<Directory "path/to/dist">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
# Require local
</Directory>
</VirtualHost>我有相同的角度应用程序,使用ng build构建并将dist文件夹添加到apache2和更高版本是我的vhosts.conf文件。完美地为我工作。
https://stackoverflow.com/questions/52870626
复制相似问题