Getting the ip address automatically on localhost using trust proxy - node.js

I have enabled trust proxy option to get the ip adress of the remote client. When the application is deployed on a remote server then I get the right address from req.ip but when the application runs on localhost then I get this address ::ffff:10.0.2.2. Does it exist a way to make thing work both in localhost and in the remote?

Related

Proxy Tunneling Through SSH

We have an HTTP proxy available on our facility's intranet. The proxy is accessed through a local IP address (192.168.x.x) and cannot be accessed from outside.
I can connect to a head node on the intranet through SSH, which has a public IP address. I can expose any port I'd like on this node.
Is there a way to somehow forward the traffic from an exposed port on the head node to this local proxy and back out to the world? I've been looking up this problem, but most solutions can only relay the traffic via SSH Port Forwarding to a local port on the device with SSH access, not another device with a different IP address.
You can try from a machine on the Internet :
ssh -L 3128:proxyIp:proxyPort user#headNode
Then on that machine, you can use localhost:3128 as proxy.
Try on a machine inside intranet first to make sure there is not security implications.

Change NodeJS local server access URL

Is it possible to change the URL used to access my local NodeJS server?
For instance, I have a Node server running on port 3000, so I can access this server directly through:
http://localhost:3000/
And other users on my network can access it through:
http://[MY_IP_ADDRESS]:3000/
Is it possible to forward this server to a local URL, like http://example/
I know that, in order to remove the port from the URL I need to bind the app on port 80, but I can't find anything about changing de URL.
Not very clear what you want, to be honest and your set-up. You use local computer or server in local network?
If you want URL in your local network isolated - that's not possible hence the URL protocol forwards requests from domain name to certain ip address.
If you want only internal access in your local network you only need to know your local ip address and make sure your firewall allows local connections. Depending on your OS run ip check in cli and voila - that's your ip.
If you want external connections then you need to have a static ip address which you should obtain from your internet provider and afterwards you need to alter you router settings and set up port-forwarding to your local machine. It will then listen to external connections on certain port and forward it to your local machine where nodejs listens (itself or through web-server). Here you can redirect your domain URL name via A-record to your static ip address of your router and port-forward to local machine.
Check out this guide for most routers for external port-forwarding.
UPD: checkout this answer

Can't connect to localhost on my application server but can access it via web

I have a website which is accessible via its URL but strangely i cannot connect to it via localhost on the server itself.
I have ensured that "127.0.0.1 localhost" is in my hosts file
I have checked that no other application is using port 80
I've ticked "Bypass Proxy Server for local addresses"
Pinging my local host from command line returns data When you go to the domain host URL the application loads successfully
Good news is my site is fully functioning but i just cannot figure out how to connect to it on localhost in my browser! any ideas?
Added details as requested;
Its a website not app if that was misleading.
The webserver is IIS on an Amazon EC2 windows instance.
The root URL is just a simple html page, which i can access via the domain URL.
However when i RDP onto the Server itself and try to access the localhost, it continually blocks me, the page wont load.
It is possible that your application is only listening on external IP address. To bind your application on all IP address, you may make your application listen on 0.0.0.0.
And could you please show the related code to help locating the problem?

What IIS or network config is necessary to be able to use a network alias from the host server?

Our web server hosts some APIs that other apps running on the same server need to call. These calls are failing with a 401.1 error.
The server has a single IP address. The server name and the network alias we use both ping to this same address.
I can browse to addresses on the server from other computers using either the machine name or the alias.
If I connect to the server I can't browse to any addresses using the alias. The machine name works locally but not the alias.
If I use the alias I am prompted to to login with my credentials. These are not accepted and then leads to 401.1 error.
How can I configure the server and/or IIS to allow the network alias to be browsed from the same server that the alias links to?

How to access localhost:3000 on AWS through NodeJS server

I have a node js server set up on AWS using Linux instance(Ubuntu 14.04) I have started the server using the command npm start How do I access the localhost:3000. And when I do it locally I am able to access all the webpages by going to the browser. How can i access it when the server is on cloud?
The localhost host name is resolved to IP address 127.0.0.1 (or IPv6 equivalent) which is routed to the loopback interface so that you cannot reach any other host than your own with that. That's why it's called localhost in the first place.
To reach your host from the outside you need to know its external IP address or a domain name that resolves to its external address. You should be able to see your external IP in the dashboard. If you can't then see this answer.

Resources