Let say I have a directory which is being hosted by Jetty or Apache (i’d like an answer for both), i know the URL including the port and i can log into the server.
How can i find the directory that is being hosted by a certain port?
I’d also like to go the other way, i have a folder on the server, which i know if being hosted, but i don’t know the port so i can’t find it in a web browser.
How can i find a list of directories that are being hosted?
This has been bugging me for ages but i’ve never bothered to ask before!
Thanks.
This is the way how to find it out for Apache. Lets say you have an URL http://myserver.de:8081/somepath/index.html
Step 1: Find the process that has the given port open
You can do this by using lsof in a shell of the server, which lists open files (and ports) as well as the processes associated to it:
We now know there is a process called “apache2” with process ID 17479
Step 2: Find out more about the process
We can now look at the environment of the process, where more information should be available:
Okey, the process executable is /usr/sbin/apache2. Now lets look at the command line.
Step 3: Finding the config of the process
Our previous examination has shown that no special configuration file has been given at the command line with the -f option, so we have to find the default location for that process. This depends on how the default command line is compiled into the apache2 executable. This could be extracted from it somehow, but obviously its the default location for Apache 2 on my machine (Debian Etch), namely /etc/apache2/apache2.conf.
Step 4: Examining the Apache config file
This again needs some knowledge about apache configurations. The config file can include other files, so we need to find those first:
A nice list. These configs tell evetything about your configuration, and there are many options that might map files to URLs. In particular apache can serve different directories for different domains, if those domains are all mapped to the same IP. So lets say on your server you host a whole bunch of domains, then “myserver.de” is either mapped by the default configuration or by a configuration that serves this domain specifically.
The most important directives are DocumentRoot, Alias and Redirect. On my system the following gives a quick overview (comments omitted):
Since the “mypath” part of the URL has no direct match, I can savely assume it lies below the DocumentRoot /var/www/, so the result of my search is that
You can do a lookup in a similar way for jetty.