如何解决自定义域而不是localhost-Angular
开发目的,我想使用自定义域而不是localhost
还有其他方法吗?
我可以找到 PHP 的解决方案,但找不到 angular应用程序的解决方案。
解决方法
更新您的angular.json
这是您应该做的:
"projects": {
"project-name": {
...
"architect": {
"serve": {
"options": {
"host": "customdomain.baz","port": 80
}
}
}
}
}
如果您使用的是Mac / linux,请更新您的主机文件
转到/etc/hosts
##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 customdomain.baz // or whatever your domain is
255.255.255.255 broadcasthost
::1 localhost
,
在hosts
文件中添加一行:
127.0.0.1 my-custom-domain.com
但是这仍然需要指定端口。您必须使用my-custom-domain.com:4200
。
要使用默认端口:80
,请用作参考this post
如果要在同一端口上运行多个站点,但服务于不同的域,请使用Nginx或Apache作为代理。
这是Nginx的示例服务器配置:
server {
listen 80;
server_name my-custom-domain.com;
location / {
proxy_pass http://localhost:4200;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。