Run Angular on AWS and link to a domain

1

I'm trying to raise an instance in AWS with Angular but I could not.

  • I created my instance in EC2, with their respective groups and routing rules (including ports 22, 80, 443 and 4200)

  • I created my elasticIP

  • With my Key Pair I have entered the SSH by Putty

  • I have installed node (10.x)

  • I have installed npm (6.x)

  • I have installed angularCLI (7.x)

  • I ran the following statement ng new myapp

  • I put ng build

  • Then ng serve

This least I would have to show the basic tutorial that has by default Angular, it tells me that it will run on the localhost: 4200 so it seems strange to me I have entered the IP that gave me the elasticIP but it says The connection has been rejected, if I add port 4200 it says that it took a long time to answer. Can someone tell me I'm running away?

In the same way I tried to do it via Elastic Beanstalk ... ran the instance, but it does not create the Key Pair so I can not enter the server that it created.

I've seen this Video to guide me, but in the end build the server by means of the node instruction and apparently runs a file made with the express framework, so I'm a little lost.

I made another instance with the same EC2 configuration but this time I just installed nginx and it worked correctly so I would rule out a routing rules problem. Something I'm doing wrong to make the application walk with either angular or with node (That the angular end uses a peculiar form of node)

At the end of this step, the next step is to link the instance to a domain that has already been purchased, so I am guiding myself with this Video

A guide tutorial would be available, if someone has one.

    
asked by Alberto Siurob 13.12.2018 в 00:27
source

2 answers

1

I know almost nothing about Angular but he writes

ng serve --host 0.0.0.0 --port 4200

to run your application. I assumed it was something like that because when I did a

netstat -tlpn

launched a:

tcp        0      0 127.0.0.1:4200            0.0.0.0:*               LISTEN      12745/ng serve

And the fact that it has the host 127.0.0.1 only makes it visible to the localhost. However, if you put the host as 0.0.0.0 it can be visible from all available ipv4 addresses.

After launching the new ng serve command, you can review with netstat and it will return something like

tcp        0      0 0.0.0.0:4200            0.0.0.0:*               LISTEN      12745/ng serve --ho

And now you can access from your browser with link

All this I did in an instance of free tier of AWS, I installed the necessary with yum and npm

And to add a domain name, AWS seems to have its own tutorial.

link

Update 1

Regarding what @JackNavaRow commented, remember that ng serve is for tests, then it would not have much "sense" (more than for learning purposes) to put it to run publicly, that is, allow any individual with access to that ip can see it. You could do that locally, even with a port forwarding.

ssh -L 4200:127.0.0.1:4200 instancia_de_aws

Then run the ng serve and in your personal browser access the address "127.0.0.1:4200".

Anyway this would be only for specific test cases.

    
answered by 13.12.2018 в 02:15
0

As a first step I would verify the connection to this port from the outside by means of telnet

telnet <ip> <port>

If it is closed, I would verify that the web page is there, connected to the host by means of ssh, use the curl command for it

curl localhost:4200

If you have shown the HTML code, you would do the last verification. Using the netstat command I see that the service is listening to all the requests through the unspecified address 0.0.0.0

netstat -tlpn | grep 4200

For the case that all the verifications are positive, I would conclude that the problem is the configuration of the server. Here I could only give ideas because I do not know the Linux distribution used. The next step would be to allow the connection to this port since the firewall could not allow it, remember that port 4200 is not the ideal one for this, I advise installing a web server such as NGINX to route the connections that arrive from port 80. If you are using Ubuntu and want to enable port 4200 you can use the ufw command

sudo ufw allow 4200/tcp

Additionally I suppose that if you are using AWS it is because you want to deploy it in production so I would not recommend installing all angular and its libraries and then use the ng serve command, for this you would build the solution using the ng build -prod command and finally remember that you can change port 4200 using ng serve --port <port>

    
answered by 13.12.2018 в 06:47