自定义域而不是localhost-Angular



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

还有其他办法吗?

我能够找到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,请使用此post 作为参考

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

以下是nginx:的服务器配置示例

server {
listen 80;
server_name  my-custom-domain.com;
location / {
proxy_pass       http://localhost:4200;
}
}

相关内容

最新更新