我已在端口 5000 和 5001 上的 AWS EC2 中托管 .Net core Web API 3.0(https://localhost:5001 和 http://localhost:5000) 我还在同一个 AWS EC2 实例上托管了 Angular(10)(默认端口 4200)应用程序,并尝试访问 api 端点。 在安全组中,我允许所有流量 - 任何地方的所有端口,允许 5000,50001,4200。
在浏览器中,当我尝试访问该页面时,我收到错误消息:net:ERROR CONNECTION REFUSED。
在本地尝试时效果很好!!
Deployment of Angular on AWS :
Install nginx in your linux sytem sudo apt install nginx
1. sudo apt update
sudo apt install nginx
2. locate your publish folder or copy to the ubuntu server and then allow the file to have permission by using cmd
3. sudo chmod 755 filelocation of ubuntu user
4. Run nginx sudo systemctl start nginx
5. Check on your default public ip on browser you will see nginx page in browser
6. Now add one server json in nginx.confg cmd sudo nano /etc/nginx/nginx.conf
server {
listen 80;
# server_name your-domain.com; # Replace with your domain or IP
root /home/web/browser; # Path to your Angular build files
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /index.html;
# Optional: Logging
access_log /var/log/nginx/angular-access.log;
error_log /var/log/nginx/angular-error.log;
}
7. Save and sudo systemctl restart nginx and then check.
8. Angular will be running on that port.
For .net API you can follow same step and publish your api code no need to change in nginx only have change in security group allow that port public and then have pm install in ubuntu for API part.