Change NodeJS local server access URL - node.js

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

Related

Access IIS https website from outside network

Currently I have a https website setup locally on the Azure VM
with a custom hostname : <websitename>.<domainname>.com and bound to the localhost 127.0.0.2
in the hosts.etc on port 443
Consider example hostname as web.microsoft.com
Website bindings in IIS are
type:https
hostname:web.microsoft.com
port:443
IP Address:127.0.0.2
Hosts.etc
127.0.0.2 web.microsoft.com
In order to access it locally on the VM itself https://web.microsoft.com/admin/login.aspx works fine.
Port 443 is open on the Azure VM and inbound firewall rule is set in windows to allow connections on 443
If I try to access it outside of the network using the public IP address this doesn't work
eg https://45.60.200.110/admin/login.aspx.
I have other non-https websites which work fine and can be accessed through the public IP ,only difference is they are not having hostname in the IIS website bindings.
Am I missing something or do I need to make some additional config?
That's the problem.
The customized hostname cannot be accessed through the external network. Because the public network does not know this hostname, nor does it bind the hostname to your IP.
For example, you can enter other custom host names at will in the browser, and you will find the same error displayed.
The solution is that you need to purchase an available public domain name from the domain name provider and bind it to IP address.
If you insist on using custom domain name, it can only be used on the internal network. In addition to the configuration made on the server side, it is also need to add the host name and IP address in the hosts file of the client machine.
45.60.200.110 web.microsoft.com

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 allow extern access with node.js

How can I allow other users to access my application that is running on localhost? Is there any package in the npm that facilitates this access?
To access your localhost (on a home network) from the internet, you need to provide a couple things.
You need a way for your clients to contact your server. This can either be via an IP address http://xxx.yyy.xxx or a domain name http://somedomain.com/whatever. If it's an IP address, then it needs to be a public IP address (not a local network address). For a home network, you would typically use the public IP address of your router that is how you connect to the internet.
If you are going to use a domain name, then you need to actually choose a domain name, register it with a registrar and configure it to point to your router's public IP address.
If your router does not have a static IP address, then you will likely need to use a dynamic DNS service that will automatically update your DNS entry to point to your dynamic IP address whenever (or if ever) it changes. There are lots of dynamic DNS services.
Then, you need to create a "hole" in your router's firewall so that incoming connections to port 80 are port forwarded to the computer where your server is running. This will typically be done in the router's configuration/security administration UI. You will "port forward" and incoming request on port 80 to whatever IP and port your server process is running on your local network.
For a more durable server installation, you would do the following:
Buy a hosting package at a hosting site that hosts the type of application you are running at the scale you expect to run it at (storage, CPUs, bandwidth). In your case, you'd be looking for a hosting service for node.js apps.
Then, you'd buy a domain name and configure it to point to the public IP address that your hosting provider gave you for your server.
Then, you'd install your server app at the hosting site and run it according to the hosting provider's instructions.
Then, a user can access your server via an URL using your public domain http://somedomain.com/whatever.
You can do so by using ngrok. In your command prompt type npm install ngrok. Once installation finished restart your command prompt and type ngrok http 3000, here 3000 is the port on which your server is running. You will get something like http://ee309.ngrok.io which is your temporary domain. You can use it until you shut your system down or close command prompt.

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.

Only allow private access to website through VPN

I know this may be very basic, but I have a website on my server that I would only like to be accessed by VPN. I have OpenVPN running on my Windows machine and it is connecting to my server with the VPN. When the VPN connects I can use the VPN's IP address to hit the site on my server. I would like to block all other methods such as the actual site IP or my domain name. Would I use htaccess? What is normally done for private access only.
Let's say that your server vpn ip is 10.1.2.3 then you should add to your apache configuration
Listen 10.1.2.3:80
so that you will bind Apache - i.e. will accept incoming requests - only to that address.
Also:
The Listen directive does not implement Virtual Hosts - it only tells
the main server what addresses and ports to listen on. If no
directives are used, the server will behave in the same
way for all accepted requests. However, can be used to
specify a different behavior for one or more of the addresses or
ports. To implement a VirtualHost, the server must first be told to
listen to the address and port to be used. Then a
section should be created for the specified address and port to set
the behavior of this virtual host. Note that if the is
set for an address and port that the server is not listening to, it
cannot be accessed.
i.e. you could leave the original listen directive (listen to all interfaces) and filter the access per virtual host having your "private" virtual host configured like that:
<VirtualHost 10.1.2.3:80>
see http://httpd.apache.org/docs/2.4/bind.html
Finally if for some reason you are restricted to .htaccess only, then you could do in .htaccess:
Order Deny,Allow
Deny from all
Allow from 10.1.2.1/24
i.e. allowing access only from your vpn subnet.
Take care that you will need to restart the web server after every change.

Resources