3

开发目的我想用自定义域而不是启动我的 Angular 应用程序localhost

有没有其他可用的方法?

我能够找到php的解决方案,但我没有找到angular application的解决方案。

4

2 回答 2

3

更新您的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
于 2020-09-24T13:17:50.860 回答
1

hosts在文件中添加一行:

127.0.0.1   my-custom-domain.com

但这无论如何都需要指定端口。你必须使用my-custom-domain.com:4200.

要使用默认端口,请将此帖子:80用作参考

如果您想在同一个端口上运行多个站点,但服务于不同的域,请使用 Nginx 或 Apache 作为代理。

这是 nginx 的示例服务器配置:

server {
    listen 80;
    server_name  my-custom-domain.com;
    location / {
        proxy_pass       http://localhost:4200;
    }
}
于 2020-09-24T13:18:14.247 回答