要将Angular部署在使用SSL的Apache2上,并通过8080端口调用Spring Boot API,您可以按照以下步骤进行操作:
生成SSL证书:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
key.pem
和cert.pem
两个文件。配置Apache2:
/etc/apache2/apache2.conf
或/etc/httpd/conf/httpd.conf
)。
ServerName example.com
DocumentRoot /path/to/angular/dist
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
ProxyPreserveHost On
ProxyPass /api http://localhost:8080/api
ProxyPassReverse /api http://localhost:8080/api
example.com
替换为您的域名或服务器IP地址。/path/to/angular/dist
替换为您Angular项目的构建输出目录。/api
替换为您Spring Boot API的URL前缀。配置Angular应用:
environment.prod.ts
文件。/api
,与Apache2的配置中的代理设置相对应:export const environment = {
production: true,
apiUrl: '/api'
};
构建并部署Angular应用:
ng build --prod
dist
目录中的文件复制到Apache2的DocumentRoot
目录下。重新启动Apache2:
sudo service apache2 restart
现在,您的Angular应用应该通过SSL的Apache2服务器上的8080端口调用Spring Boot API了。
下一篇:Angular不同的构建