deploying WT web app on google cloud - web

I have build a wt (witty) hello world example and I am trying to deploy this on a Google Cloud instance. It seems to run fine locally (hence it has all the necessary library dependencies). However, I am not able to it to deploy on the server.
I am trying (using my actual http address which is different from the example below)
./hello --docroot . --http-address 105.150.47.754 --http-port 80
but it responds with
Error (asio): bind : cannot assign requested address
It seems to work fine using (0.0.0.0/0)
The cloud instance allows HTTP tcp/80 traffic.
I have tried
setcap 'cap_net_bind_service=+ep' ~/hello
to allow non-root users to publish on ports below 1024, but also to no avail.
Any suggestions?
Cheers, Mike

If you are unable to listen on the specified IP address, one of the following is likely true:
1) Something (such as a web server) is already listening at that address on port 80, or
2) The IP address you are using is not assigned to one of the machine's network interfaces.
Using (0.0.0.0/0) with port 80 tells the Wt web server (wthttpd) to listen on all available local interfaces. Therefore, using that address will work with any available network interface assigned any IP address with port 80 available.

Related

Why can't this port be accessed outside of the local machine?

I have a node.js server running on an EC2 instance. I can connect to my index.html page by visiting 12.345.678.900:2112 (not the actual site, just an example). Later on, I open a socket connection that is listening on port 3113. When I'm on the machine itself, I can access the webpage through the localhost (localhost:3113/foo). When I try to access it outside the local machine through 12.345.678.900:3113/foo, I can't access it. The socket connection is successful and the server is listening on 3113 when I run netstat, but it just doesn't allow me to access the page. I have a feeling my ports may be blocked, but from what I tell it shouldn't be. I don't have this problem when I run this server on my local machine however.
Incoming Connections
Solution:
Since curl was telling me port 3113 wasn't open, but it wasn't being blocked on AWS I looked through my code and realized that I opened port 3113 but then closed it soon after, which meant that while I was getting a log statement telling me the port was open since it was closed almost immediately I wasn't able to access the port.
When you setup TCP listening port, you had to specify IP address and port number. If your server is listening on 127.0.0.1:3113, then it won't be accessible from its external IP address. You can also specify the special 0.0.0.0 as the IP address, which indicates that you want to listen on that port in "all" IP addresses (for some definition of "all").
If your machine have multiple network interfaces (e.g. multiple network cards, or virtualised network interface), then it's possible to have the same ip address actually being on different networks and you'll have to specify the specific network interface when you listen to them. But if you did set up something unusual like that, you probably already know about these networking stuffs already. Note that if you have Docker or virtual machines, they may also creates virtual network interface for each containers/VM.
On AWS/EC2, your machine may also have internal IP address that's only accessible from your VPC and an Elastic IP which can be accessed directly from the outside world. You didn't say which "external" IP address you were using.
Finally, you may have firewall installed on the server. ipfw or iptable may have rules blocking external listening port.

NodeJS host two application on Single server using two IP addresses and same port 443

I have two different nodejs + expressjs applications with different SSL certificates. I got another IP address for my second app. I have only one port enabled i.e 443. When I run first application it runs successfully, but when I try to run second one it trows port already in use error.
Please note I am running both application on different IP addresses.
This has nothing to do with the number of interfaces/IP addresses you use. A port on a machine can only be used once. In this case, your first application already listens exclusively to it.
The best way is to use a web server or reverse proxy (e.g. HAProxy, nginx, Apache) listening on all interfaces to handle incoming requests on port 443 and forward the traffic to your applications based on the IP address – or even better (sub)domain name – of the request. Then you can run both applications on a separate port > 1024 that doesn't require root rights to bind (which is also a security issue):
Example:
Request to IP 10.1.10.1 → +---------------------+ → Forwarded to app 1:80441
| Reverse Proxy:443 |
Request to IP 10.1.10.2 → +---------------------+ → Forwarded to app 2:80442

Cannot connect through external IP in Google cloud Compute engine instance

I created compute engine instance in GCP to deploy my web app.It works fine inside the instance (localhost:8080).
However, using the external Ip address, I'm unable to access it even though I have allowed for 0.0.0.0/0 for all instances by the firewall rule.I added both port tcp:8080 and tcp :8444 but It does not allow to connect even 'Telnet'.
Connecting To 35.185.98.244...Could not open connection to the host, on port 8444: Connect failed
Connecting To 35.185.98.244...Could not open connection to the host, on port 8080: Connect failed
Anybody can help me to solve this issue?
my git url: https://github.com/ChkBuk/myexamples/tree/master/SyneBiz
Take a look at the Firewall Rule in the GCP. Make sure that you allow ingress traffic for the port 80 (since you are accessing it from the browser). The ports 8080 and 8444 are local ports accessed internally. These ports are not exposed to the public. You have to make sure that there is a forwarding rule that redirects the traffic from port 8080/8444 to port 80.
Eventually, try to test the URL connection and the ports within the compute engine instance, or outside the GCP. Below are some examples:
$ curl http://[external-IP-vm-address]:80
$ telnet localhost 80
$ nmap <external-ip-vm-address>
$ netstat -plant
There are other network tests that you could perform. You may consult this discussion thread from Stackexchange.
Lastly, it could be that the ports 8080 and 8444 are already being used by other processes. For this reason, you are unable to connect to them.
Try the following troubleshooting steps.Type:
$ netstat -tulpn
This command above will display a list of all processes running on their respective ports. If the port 8080/8444 are there, take a look at the existing process running on it. You may then kill that process. For more information on troubleshooting the processes running on port 8444 and 8080, you may consult this article.

Expose node js app with host as localhost on kubernetes

I have spent whole day looking for an answer why my node js app is not reachable from the internet when I run it on Kubernetes with loadbalancer as a service type. The solution was to change host from localhost to 0.0.0.0 in node js server app definition, but I still don’t know why?
I hope this saves one’s time in the future.
When you say that you set the host I guess you mean what the app is told to listen on in the listen function like express app server . listen all intefaces instead of localhost only You can bind to a particular address or leave it open to all by using the 0.0.0.0 mask (the zeros function as a mask for matching rather than a true IP address - https://stackoverflow.com/a/20778887/9705485).
I imagine you had your app running fine locally and were able to access it from your host machine with your localhost configuration. This would be because your local machine would be accessing it in a way that conforms to the mask. Your config was effectively saying only localhost can access this app. So when you ported to Kubernetes then your machine has to go over a network and the incoming connection was then your machine's external/public IP address, which then did not match the localhost mask. So to get it to work you changed the mask to make it open to all IPs.

how to run nodejs in google compute engine external ip with 2 separate port

I'm facing an issue.
I have created vm instance on google compute engine. vm instance external ip is: 104.198.225.177. accessed ssh and installed nodejs. now I want to run 2 nodejs script one in port 8000 another in port 9000.
if want to run and access 2 nodejs url like this: http://104.198.225.177:8000 and http://104.198.225.177:9000
I have created script but when I start and try to access in browser using vm instance external ip, like : http://104.198.225.177:3000/ but its not working. I tried in ssh cur like : curl localhost:3000/ and its working but using external ip its not working.
when I add ip address while starting nodejs like this:
app.listen(9000,"104.198.225.177"); I'm getting this error:
listen EADDRNOTAVAIL 104.198.225.177:9000 at Object.exports._errnoException
any help appreciated.
Ensure that you've allowed traffic from external sources to reach certain ports of your GCE instances in Networking Firewalls section.
Solved: Also ensure that your application is bound to 0.0.0.0/all interfaces and addresses, not just VMs public IP address.

Resources