Deploy Go webserver to Google compute engine - http

I just started to test Google compute engine. Now I'm trying to deploy my Go (golang) application on it, so that it can be reached from outside. I use compute engine in favor of the app engine, since my application requires a MongoDB database.
I did the following:
create compute engine instance
setup up firewall so that port 1234 is open and IP is static
install MongoDB
upload my application
start
The application starts just fine. But I cannot reach it from outside if I open it in my browser with ip:1234. I also tried to start it on port 80 as root user, but this didn't work neither.
The server is configured as following:
{
"host": "localhost:1234",
"dbhost": "localhost",
"db": "dbname",
"logfile": "log"
}
When I'm using an apache server it servers port 80 and the page is displayed... OS is ubuntu 14.04.
The main simply adds some handlers to a mux and adds a FileServer to the public dir:
mux.Handle("/", http.FileServer(http.Dir(public_dir)))
// [...]
if err := http.ListenAndServe(cfg.Host, mux); err != nil {
panic(err)
}
So what's the issue here?

Try changing host from localhost to 0.0.0.0, because right now it's only listening to "inside" requests.

Related

How to reach a restrserve api from rstudio server on aws?

I am trying out the very interesting package RestRserve from with RStudo server that I installed on an AWS instance.
This is de code I use:
library(RestRserve)
app = Application$new()
app$add_get(
path = "/hello",
FUN = function(request, response) {
response$set_body("Hello from RestRserve")
})
backend = BackendRserve$new()
backend$start(app, http_port = 8080)
I think the app is up and running, the message seems right:
{"timestamp":"2020-01-26 07:42:30.957686","level":"INFO","name":"Application","pid":1872,"msg":"","context":{"http_port":8080,"endpoints":{"HEAD":"/hello","GET":"/hello"}}}
-- running Rserve in this R session (pid=1872), 2 server(s) --
(This session will block until Rserve is shut down)
However, when I try to reach the app using the ip address of the instance like this: http://35.180.45.129/hello the browser says the site can't be reached.
Did I miss something? Any ideas about why this doesn't work?
Likely you need two additional steps:
make sure you allow traffic from internet to 8080 port
make sure you use public IP (or better DNS) of your instance

Meteor DDP call between containers on same host

This Meteor App server code tries to use the method of another Meteor worker. both the app and the worker are in a separate docker containers on the same server EC2. The worker is running on port 9000.
When the App fires a method appCallingWorker, I expected to see the worker container logs out the string 'worker called from App' but all docker logs containerID gives is many lines looking like this:
stream error Network error: ws://localhost:9000/websocket: connect ECONNREFUSED 127.0.0.1:9000
How can I use the methods of the worker from the App? thx
//App/server/main.js
let workerConn = DDP.connect('http://localhost:9000');
Meteor.methods({
'appCallingWorker': () => {
workerConn.call('workerMethod');
}
});
//Worker/server/main.js
Meteor.methods({
'workerMethod': function () {
console.log('worker called from App');
}
})
edit
The EC2 is a Container Instance in AWS ECS. and the containerDefinitions.portMapings.containerPort and hostPort are both set to 9000.
edit 2
iptables -L -n on the docker host shows the ip of the container listening on 9000, I replaced localhost in the code with said ip and now it works. But Said ip can change if host reboot or container restarts... another problem to find a solution for.
i had this same problem trying to communicate between docker containers. you're going to have to use the external ip:port address of the server your containers are on.

Openshift + NGINX RTMP

I've been trying to stream flv content from my openshift cartridge using nginx + rtmp module.
On my local machine, with the attached configuration, everything works just fine (I use ffplay for testing, e.g. ffplay rtmp://localhost:8080/test/streamkey)
When I try with the same configuration on openshift, I get the following error:
HandShake: Type mismatch: client sent 3, server answered 60 f=0/0
RTMP_Connect1, handshake failed.
However, if I enable port-forwarding and test the stream server using ffplay rtmp://127.0.0.1:8080/test/streamkey, everything works fine. here are my port forwardings:
rhc port-forward myappname
Checking available ports ... done
Forwarding ports ...
To connect to a service running on OpenShift, use the Local address
Service Local OpenShift
------- -------------- ---- -----------------
nginx 127.0.0.1:8080 => 127.10.103.1:8080
My cartridge is a "diy-0.1" cartridge. nginx 1.7.6 (also tested 1.4.4) + rtmp-module.
I suspect there are some issues with some proxy (apache?) that uses openshift for handling gears, maybe it does not allow rtmp headers(?)?
NB: Configuring nginx http-only works fine.
Can anybody help? I'm stuck, I think this is the first time I ask something on stackoverflow :-)
The nginx configuration (NB: the "play" path and the IP:PORT are taken using the openshift environment variables.):
rtmp {
server {
listen 127.10.103.1:8080;
chunk_size 8192;
application test {
play /var/lib/openshift/54da37644382ece45c000139/app-root/runtime/repo/public;
}
}
}
There is an apache proxy in front of your application on OpenShift Online, and it is possible that the content is trying to be streamed as HTTP traffic instead of RTMP traffic, that is why you are getting the content mismatch, but if you do it through the port-forward, you are gaining direct access to your application and bypassing the proxy. That is why it works fine with the port forward. There is currently no way to bypass the apache reverse proxy through the public ip, please see this developer portal article for more information about how requests are routed to your application: https://developers.openshift.com/en/managing-port-binding-routing.html

Can't access port 8080 on EC2 (AWS)

I just started a new AWS EC2 instance. In the instance's security group I added a new rule to open port 8080. I also stopped the iptables service on the instance, per another post. So in theory this port should be wide open.
I started my RESTful service on 8080 and was able to access it locally via curl.
When I come in with curl remotely I get an error saying it couldn't connect to the host.
What else should I check to see if 8080 is truly open?
I started my RESTful service on 8080 and was able to access it locally via curl.
What kind of technology is your RESTful service based upon?
Many frameworks nowadays listen on localhost (127.0.0.1) only, be it by default or by means of their examples, see e.g. the canonical Node.js one (I realize that port 8080 hints towards Java/Tomcat, anyway):
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
The log message generated by starting this is Server running at http://127.0.0.1:1337/ - the emphasized part is key here, i.e. the server has been configured to listen on the IP address 127.0.0.1 only, whereas you are trying to connect to it via your public Amazon EC2 IP Address.

How to host a TcpClient/listener online (I want to host my chat server online)

I have a chat server that i create for my window phone app. Right now it working on my local computer, how do i make it online so everyone can connect to it.
Chat server:
TcpListener chatServer = new TcpListener(4296);
Chat client:
TcpClient client = new TcpClient("127.0.0.1", 4296);
How do i forward the port so i can host it online!
In order for the world to see it you need to host it somewhere with a public IP address. You will then use this IP address in the client connection:
Chat client: TcpClient client = new TcpClient("xxx.xxx.xxx.xxx", 4296);
Depending on your platform you could use Google App Engine or Amazon Web Services to quickly deploy your application.
That depends on your router/gateway. Check your router's documentation for more information how to forward ports.
Basically If you want to deploy your app online you need your own Domain(you get your own IP to host), you can use Cloud Server to deploy(these is a good option, since you can deploy for free but storage is limited in free edition), Or else you can Host on your Routers IP Address.
If you are using first two option then these is a python script to start a listener service on given IP and port.
Here:
import socket
import sys
HOST ='' # Symbolic name, meaning all available interfaces
PORT = 8000 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
try:
s.bind((HOST, PORT))
except socket.error as msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
#Start listening on socket
s.listen(10)
print 'Socket now listening'
#now keep talking with the client
while 1:
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
s.close()
These is just a sample, you can put all of Your code from Your PC to Cloud and edit the changes in IP.
And if you want your router to listen to the client then you have to go to the routers login page, for most of the router it is 192.168.51.1, go here and login as administrator, Then you should go to firewall configuration over there you will find an option of custom server, then click on it and then there configure the ip address, port,etc to host.
I prefer you to watch these full video to understand properly: Here Video
In these video he is hosting for exploitation purpose you can host to do any other activity.
Thank You.

Resources