Serving static file locally on a subdomain - node.js

I have a web application with a Vue front-end and Golang back-end.
I am trying to deploy the front-end static files on local work network.
I am serving them with http-server on a windows server connected to the network.
Rightnow if I execute
http-server -p 50
I am able to access the application by going to http://hostname:
50
However, the goal is to deploy it on
http://hostname/app
Is it possible to do it, if so what would be the approach in terms of best practices.
Note: For deployment of the Vue static files either a node server or golang server would work.

Let's start with a bit of terminology correction.
http://hostname is not really a domain. It is just a URL referring to
an unqualified host name. A domain would typically be something like
yourorgdomain.com (or .org or .edu or other such top level domains;
let's stick with .com for now). Your hostname (when fully qualified
under the domain) would be identified as hostname.yourdomain.com.
Therefore, your hostname is mapped to a subdomain. For the sake of
simplicity, if being referred from another host on the same domain
and network the domain part is implied so the network understands that and something like http://hostname just works. The mapping is somewhere
in your network configuration.
http://hostname/app is not a subdomain of http://hostname; it's just
a path (or more correctly a resource) under the same host http://hostname. A subdomain would be something like http://app.hostname http://app.hostname.yourdomain.com when fully qualified)
Now for some explanation of how these URLs work:
Consider the URL http://hostname:50. The http:// part is referring to the protocol and :50 part at the end to the port number. By default http uses port 80 (https uses 443). So if you configure your web server to serve on port 80, the :50 part is redundant.
Now you just need to organize your website content such that it is available at http://hostname/app URL. The simplest way to do this for static sites is to host your content under the /app/... directory relative to where your site root is mapped to. So if your web server is serving the directory .../public on http://hostname, just move your content to .../public/app like you do for file paths. That's all
Caveats
However, if you truly want to host your app under a subdomain like http://app.hostname/ then that's a whole different story, but in brief, the lowest level subdomain being referred to (app) has to be mapped to a host and the intermediate subdomain can't be a host, just a subnet. You can't have further subdomains under a host. That's why typically websites addresses refer to http://www.example.com where the www is mapped to the host actually running the website
All of this ignores how reverse proxies and load balancers work and pretend to exhibit this above behavior but that another long story for another day.

Related

SSL Certs for single IP- two ports, same URL website

We've a project that is to go live very soon and we ran into this issue when dealing with developers. This is two JDEdwards (ERP) website which are hosted on a single IBM WebSphere webserver, currently using a FQDN, and different ports assignment for DEV and TEST users. Websites as such are -
DEV
https://jdeweb01dev.corporate.company.com:100/jde/owhtml/
TEST
https://jdeweb01dev.corporate.company.com:101/jde/owhtml/
There is only one IP configured for the above server FQDN but we will eventually give common name like JdeDev.company.com JdeTest.company.com or something.
We want to implement SSL cert for our Test/Dev environments, but how would we implement this on IIS or IBM Web SPhere, as well as on DNS level. Sine the only difference between the URLs is port numbers and both lead to different websites. I'm open for suggestions on how we can improve the design as well or how to make the current design work.
Another important thing to consider, the two websites will be accessed between two different Domain Forests which have transient Trust. This is a JDEdwards project.
Appreciate any help on this!
In order to configure HTTPS binding in IIS site binding, just configure a certificate in IIS site binding module.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-an-iis-hosted-wcf-service-with-ssl
Also, this could be accomplished by the Netsh http command.
netsh http add sslcert ipport=0.0.0.0:8000
certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6
appid={00112233-4455-6677-8899-AABBCCDDEEFF}
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-a-port-with-an-ssl-certificate
After you have set up the FQDN in DNS entries, you could specify the Hostname field in order to access the service with the server fully qualified domain name.
Feel free to let me know if there is anything I can help with.
WebSphere supports multiple virtual hosts, each with its own alias(es), which can be a combination of DNS name and port. The built-in default_host will typically have an alias for the server/node name and the * wildcard for all ports. You then assign a specific virtual host to an application when you deploy it.

Want to have app (Server:Port) to have friendly alias - Understanding Host Alias / DNS / A Record / CNAME

I am trying to get my head around Windows, Networks and Domains.
I currently have a server - svr. This is on my domain companyname.co.uk
I can connect to server and ping both svr and svr.companyname.co.uk.
On this server I have a number of applications with web access; TeamCity, Octopus etc. We currently connect to them by browsing to svr:xxxx where xxxx is the port of the web app host (http://svr:9090/ for TC)
I want to create friendly alias' - for example teamcity.companyname.co.uk would point at svr:9090, octopus.companyname.co.uk would point to svr:8090.
However, not being experienced in this area I can't seem to find relevant documents or sites that fully explain what I am looking for.
First, to make one thing clear: when you visit a web page like http://example.com, your web browser is actually making a request to example.com:80. This is done transparently because port 80 is the standard port for the HTTP protocol. As you know, you can request a non-standard port by appending it to the domain name in the URL: http://example.com:888/.
Unfortunately, you cannot have a domain name "alias" that somehow includes a non-standard port - your browser will always try to use port 80 if you don't specify a port.
One solution would be to use a proxy - nginx, apache, lighttpd, and others can all do this.
The idea is that you set up a proxy server that is listening on port 80 on your host. It waits for connections, then forwards those connections to a different server (on the same host, or on a different one) based on some rule. So, for example, you might have rules that look something like this:
IF host = teamcity.companyname.co.uk THEN forward to teamcity:9090
IF host = octopus.companyname.co.uk THEN forward to octopus:8090
The syntax for these rules vary widely between different proxy configurations, so this is just an example.
Note that this is not a redirect - the user's browser connects to teamcity.companyname.co.uk for all requests. It's the proxy that sends the request on to a different service and forwards any responses back to the client "behind the scenes".
These proxy configurations can get quite complex. For example, what if your teamcity application serves a page with a link on it that points to http://teamcity:9090/path/to/page? The user's browser is going to fail if they click on that link. Fortunately, proxies can be configured to rewrite URLs like this on the fly. You'll need to do some research to tailor this solution to your situation.

DNS Changes: Pointing one subdirectory to another host

Short Question:
Is it possible that example.com points to an IP address, but example.com/something points to another IP?
More Details:
example.com was previously hosted with my client's host company. I have designed a new website for them and now host it myself (by pointing their IP to mine). They are now letting me know that there used to be a sub-directory where another application was hosted under. It would take me a while to re-install that application in the new host, I was just wondering if it'd be possible to serve any request to that sub-directory through the old host/IP.
That's not possible. Resolving the host (example.com) is a separate task (DNS query) from connecting to the http server (HTTP connection) that the host points to. None of the URL, except for the hostname, is queried via DNS so there is no way that DNS can be made to behave differently based on other parts of the URL as it doesn't see it.
A subdomain is part of the hostname and that's why www.example.com and www1.example.com can point to different addresses. If you need to have www.example.com/something go elsewhere, you'll need to use HTTP redirects.

Setup virtual hosts file to host the source code from remote server

I would really appreciate your support for the below inquiry
Current Situation:
I have a web app (contains a module to upload documents) on a Linux Apache server "A" that can only be HTTP-ed through the intranet.
Required:
Another Linux Apache server "B" is required to host the same web app, while maintaining the source code on server "A" only. Server "B" can be HTTP-ed through the internet and intranet.
Blocking points:
Under the current circumstances we are unable to host the website on server "B" directly (which would seem like the logical solution).
Question:
Is it possible to setup the virtual-hosts of the httpd.conf file for such requirement?
Research:
Usually most of my findings were posts about deploying a load-sharing/load-balancing solution (not my objective), or setup a two-way synchronization process between "A" and "B" (last resort solution).
Googled strings:
share website between two servers, host website on two servers, virtual host to another server, run single website on multiple servers setup, virtual host for website on another server, host a website on two different servers, setup two linux servers to host the same website
Server Details:
Server A:
Server IP: 192.168.xxx.xxx (accessible through the intranet only)
Hosts the website source code
Apache server
OS: RHEL5
Server B:
Accessible through the intranet and internet
Apache server
OS: Same as A (RHEL5)
Summing up what you've probably found yourself by now: unfortunately, there are two things that are called proxying. The you are interested in is called a reverse proxy, in which B will take requests and forward them to A. The client never sees that A even exists. There are few security concerns, depending on what angle of security you look at:
server A only ever sees requests from B, not the original client, so any IP-based restrictions you want should be configured on server B.
The usually mentioned security concern is that a (forward) proxy will ask arbitrary servers for things on behalf of the client, so it masks the client's identity. I don't think you need to worry about this as long as you put ProxyRequests Off to disable forward proxying.
Server A might accidentally reveal its IP, which you might not be comfortable with. When B passes back the answer to the clients request that it has received from A, it will not look at the payload. So, if you return HTML documents, they better all have only relative paths. I think this might be the problem you are having: if your code still contains references to 192.168.x.y, those won't work for the external client. If you are changing paths (i.e. you have something like ProxyPass /somepath http://internal-server/otherpath), things become even more complicated, so try to avoid that. (In general, your backend application would need knowledge of what its publicly-visible URIs are. How to do this depends on the application.)

deploying a node.js on a new domain

I have a server that runs different websites on different ports. All of them (but one) are Apache servers and thanks to webmin, I managed to have, for instance, example.com point to 123.123.123.123:80 and example.fr to 123.123.123.123:8000, somehow automatically
I am now running a nodejs server on the same machine, so the 80, 8000, and many other ports are already taken. My nodejs listens on 8008. I have another domain name, say example.org, and I want it to point to my nodejs website, but I simply don't know how to do that! I have updated the DNS and everything is pointing to 123.123.123.123 (my server's IP). I want to avoid using an ugly example.org:8008/ for everything on this node server. How can I make it point implicitly to the 8008 port?? I must add that I cannot afford to take down the apache servers ;)
DNS only provides name to ip address mapping. It cannot handle ports. What you can do instead is to set up a proxy server listening on port 80. The proxy server can then return data based on the host header.
Your best option is to just redirect the request from Apache. Otherwise you can use a reverse proxy like Nginx. Also, you can write a lightweight proxy in node... check out this page

Resources