node.js on hosted account (non localhost) good install server started but (not found) - web-services

I installed node.js on a hosted Apache server. The simple server I placed on the server runs fine, but when I go to the website I cannot see the website.
I initially tested this on my local machine and it works fine, but I need this on a production website. How can I do this.
My Node.js code
[code]
// Load the net module to create a tcp server.
var net = require('net');
// Setup a tcp server
var server = net.createServer(function (socket) {
// Every time someone connects, tell them hello and then close the connection.
socket.addListener("connect", function () {
sys.puts("Connection from " + socket.remoteAddress);
socket.end("Hello World\n");
});
});
// Fire up the server bound to port 7000 on localhost
server.listen(1337, "localhost");
[/code]
// Put a friendly message on the terminal
console.log("TCP server listening on port 1337 at localhost.");
Then I run node test.js
Response : TCP server listening on port 1337 at localhost.
Then I go to www.mywebsite.com:1337
Oops! Google Chrome could not connect to www.mywebsite.com:1337
So I tried using the actual IP
server.listen(1337, "xx.xx.xx.xx");
And the URL
server.listen(1337, "http://mywebsite.com");
// this actually broke the server immediatly
So how can I do this?

You will need a firewall rule to allow incoming traffic.
iptables -A INPUT -p tcp --dport 1337 -j ACCEPT
and do not bind to localhost, but on the port only:
server.listen(1337/*, "localhost"*/);
http://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback
EDIT: This comments out the host, so your server will listen on all adresses (this is the same as:)
server.listen(1337);
If you still encounter problems, this is most likely a firewall problem.

Related

code-server WebSocket close with status code 1006

I am trying to install code-server 3.6.2 on a cloud platform. I have tried both AWS and digitalocean machines but in both systems, I can open code server but it gives an error "WebSocket close with status code 1006".
I have followed the procedure from https://www.digitalocean.com/community/tutorials/how-to-set-up-the-code-server-cloud-ide-platform-on-ubuntu-20-04
code-server uses websocket to connect.Do you use HTTPS?
If so, you should Use wss to forward ws.like this:
// forward websocket (wss -> ws)
httpsServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head, {
target: 'ws://...',
ws: true
})
})
Usually this and other errors happen when you use code server locally
To solve it you can use the --link parameter that gives you a url with temporary https, or you can also use ngrok
//Option 1
code-server --host 127.0.0.1 --bind-addr 0.0.0.0:9000 --auth password --link
//Option 2
code-server --host 127.0.0.1 --bind-addr 0.0.0.0:9000 --auth password
ngrok http 9000

Can't connect to django server in browser

Tried running it from local host but in cmd prompt its fine as i see "Quit the server with CTRL-BREAK.". But not connecting in browser. Also tried telnet to connect to that port, but failed. what could be the reason? can't be a proxy as even telnet is not workiing
Add the port number, probably 8000, after the url in the browser: http://127.0.0.1:8000.

Can't communicate on open port between terminal sessions on Amazon instance

I realise that the firewall should not block traffic moving between terminal sessions on the same server, but I have included detail of my firewall here as it might be related somehow. The crux of this problem is "What linux/AWS setting could be stopping me from communicating on a port on the same instance"
I have an amazon instance (not build by me) running Debian. I am trying to get an email relay running, but that question is in another post. For starters, I just want to make sure that a port is open. The way I do this on other servers is, I make sure the firewall is not blocking the port, and then get netcat to listen on that port. So, for my instance I went to AWS security management and opened port 2525 both UDP and TCP
nothing is blocked outbound
and checked the local firewall
root#lamp # iptables-save
# Generated by iptables-save v1.4.14 on Sun Feb 28 10:36:57 2016
*nat
:PREROUTING ACCEPT [727933:41936189]
:INPUT ACCEPT [727933:41936189]
:OUTPUT ACCEPT [4341889:262878645]
:POSTROUTING ACCEPT [4341889:262878645]
COMMIT
# Completed on Sun Feb 28 10:36:57 2016
Then I ran netcat to listen on port 2525
root#lamp # nc -l 2525
logged on via a different terminal session to the same server
root#lamp /home/www# nc localhost 2525
localhost [127.0.0.1] 2525 (?) : Connection refused
root#lamp /home/www# netstat -anp | grep 2525
root#lamp /home/www# telnet localhost 2525
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
I try this on my ubuntu laptop or on my rackspace instance, the nc command should get me a kind of chat session which I terminate with a CTRL^D.
I am not too familiar with the way Amazon do things, so I guess I am missing some AWS web interface, but what confuses me is I would expect all traffic to be free to travel between different sessions on the same localhost. Any light that could be shed on allowing traffic on this port would be appreciated.
AWS Security Groups wouldn't be getting involved here in terms of opening + connecting to the server locally.
It's only relevant when trying to connect to and from other servers.
I suspect your issue is a Linux configuration issue, but of what flavour I do not know.

Why can I connect to http://127.0.0.1:8000/ but not to http://192.168.1.6/

I'm running OS X Mountain Lion on a machine with local IP address 192.168.1.6 (as reported by both the Network utility and ifconfig) and am running a local (Django) development web server on port 8000 that I would like to connect to from a virtual machine running a guest OS on the same machine.
On the host OS (ie, OS X running on the metal of the machine w/ address 192.168.1.6) I can connect to my test web server through the browser by navigating to 127.0.0.1:8000; or localhost:8000; but not when using the machine's local IP address. Here's what makes this extra confusing:
The router is not filtering the ports; and, just to be sure, I've set it to explicitly forward ports 8000 and 22 to 192.168.1.6; And speaking of port 22,
When I start the SSH service, I can connect (from the command line) via ssh 192.168.1.6
It's not a browser issue, because I also can't telnet to 192.168.1.6 port 8000 (connection refused) while I can telnet to 127.0.0.1 port 8000, and I can also telnet to 192.168.1.6 port 22
The firewall is set to off (as reported in System Preferences) but to be extra safe, I've also set an ipfw rule to allow everything through
Here are the ipfw rules:
00100 allow tcp from any to any dst-port 8000
65535 allow ip from any to any
Here is additional confirmation that the port is, indeed, being listened to by my test server:
netstat -an | grep 8000
tcp4 0 0 127.0.0.1.8000 *.* LISTEN
so what's going on here? Somehow port 22 is being treated differently than port 8000, but every place I can think to look for those differences I can't find any. Why can't I get into this machine's port 8000 using its local ip address?
When you start Django development server you need to give the address explicitly:
python manage.py runserver 192.168.1.6:8000
Or if you want the server to run on all interfaces you can use:
python manage.py runserver 0.0.0.0:8000
In other case Django development server defaults to running on the local interface only.
The problem for me was I accidentally quit the server whenever trying to copy the server address. So instead of using ctrl+C just write down the address into your browser.
I solved the issue.There are a few things you might be missing.Listing them below-
1.Once it starts the server, do not press Ctrl+C anyhow .u might be pressing it to copy to url and that accidently closes the server due to which it might be happening.
2.instead of http://127.0.0.1:8000/ ...change the port number to http://127.0.0.1:8080/ ...That would work.
3.Try changing the firewall setting and allow the app.
4.Try opening it with different browsers and incognito too.
The above steps helped solve my issue.Hope they help u too...:)

Pycharm: testing from anther computer in local network

I am using Pycharm and testing on local dev server. All goes well until I try to connect to the local dev server from another laptop (windows).
My dev server is 127.0.0.1:8000 on a mac. On the second computer, I am able to ping the server's LAN ip 10.0.2.2 successfully. But enter 10.0.2.2:8000 in browser address bar doesn't connect to anything.
telnet 10.0.2.2 8000 in command line also fails.
How can I do this?
Listen to address 0.0.0.0 instead of 127.0.0.1
This means it will listen to all, you can listen to specific IP but this would work on both local and network.
For beginner like me, screenshot can help.
If leaving Host field to be empty, it will default to 127.0.0.1, which is not we want in such situation.