where localhost points?

Questions about Wi-Fi and other network devices, file sharing, firewalls, connection sharing etc
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

where localhost points?

Post by dancer_69 »

I hope that this is the right section for this question.
Before a long time ago I've created a startpage and I use it in firefox. I used an addon to replace the default startpage in which I couldn't use the file choose method. This forced me to use a local web server(I think) to manage to use the local file. The problem is that I don't remember where I copied the files needed for my startpage and now I want to change something and I cannot find them. In the addon I have set "127.0.0.1"(localhost) as address for the page, but I don't now where in my filesystem it points. I tried /var/www/html in which I thought that this is the place, but seems that it doesn't. I also opened /etc/hosts file in case I did something there but there is nothing related.
So, is there any way to find where localhost points, so to find the folder in which are the startpage's files and edit them?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: where localhost points?

Post by rene »

"localhost" does not point to anywhere in the filesystem in a direct sense; it "points" to the server (web-server, in your case) on the local machine and it's only said server that knows to in response to requests serve up content from whichever source it is configured to.

That is, you'll need to identify what is in fact listening on 127.0.0.1:<port> (normally 80 for HTTP, 443 for HTTPS) and view its configuration. sudo lsof -P -i -n -sTCP:LISTEN could tell you what's listening for HTTP(S) requests on 127.0.0.1 and thereby guide you to its configuration.
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

Re: where localhost points?

Post by dancer_69 »

Thanks.
I tried this command, but I didn't find something in *:80 or *:443(no entry for it). For *:80 there are some "apache2" entries(www-data user). For 127.0.0.1 there aren't any entries for those ports. There are some "python" entries to :5054 and one entry "container" to :45415.

EDIT:
using "127.0.0.1:80" on firefox address bar takes me to my startpage, so seems that is one of the "apache2" entries. These are the entries:

Code: Select all

apache2    1756            root    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    1759        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    1760        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    1761        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    1762        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    1763        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    2428        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    2689        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    2690        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    2923        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
apache2    2924        www-data    4u  IPv6   32499      0t0  TCP *:80 (LISTEN)
Last edited by dancer_69 on Sun Jan 05, 2020 10:59 am, edited 1 time in total.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: where localhost points?

Post by rene »

The * means "any" in this context so Apache seems to be the server you're looking for. Try and see if https://www.tecmint.com/change-root-dir ... eb-server/ is useful in determining your DocumenttRoot.
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

Re: where localhost points?

Post by dancer_69 »

The default DocumentRoot is /var/www/html, but seems that another directory used. I tried to restore the default apache's index.html page(I have it) but still 127.0.0.1 opens the startpage, which means that it doesn't use that directory.
User avatar
chazz_tsc
Level 1
Level 1
Posts: 39
Joined: Sun Mar 18, 2012 7:55 pm

Re: where localhost points?

Post by chazz_tsc »

You can also look in /etc/apache2 for configuration files that define web sites. If you followed standard practices, which granted you may not have, there will be a directory /etc/apache2/sites-enabled that contains links for the sites you created; that will have a <VirtualHost> section that contains a DocumentRoot pointing to your files. If you didn't follow standard practice, that section will likely be at the foot of /etc/apache2/apache2.conf .
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

Re: where localhost points?

Post by dancer_69 »

There is nothing there unfortunately. Also apache.conf has only /var/www/html.
There is a long time, so I don't remember how I setted up.
User avatar
chazz_tsc
Level 1
Level 1
Posts: 39
Joined: Sun Mar 18, 2012 7:55 pm

Re: where localhost points?

Post by chazz_tsc »

Can you post the contents of any <VirtualHost> sections in apache.conf? Also if there are any IncludeOptional lines, those may point to directories where more configuration information is found; the contents of those directories would be useful.
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

Re: where localhost points?

Post by dancer_69 »

I didn't find any virtualhost section in apache2.conf. Here are the contents of the file:

Code: Select all

# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#	/etc/apache2/
#	|-- apache2.conf
#	|	`--  ports.conf
#	|-- mods-enabled
#	|	|-- *.load
#	|	`-- *.conf
#	|-- conf-enabled
#	|	`-- *.conf
# 	`-- sites-enabled
#	 	`-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


# Global configuration
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
#Mutex file:${APACHE_LOCK_DIR} default

#
# The directory where shm and other runtime files will be stored.
#

DefaultRuntimeDir ${APACHE_RUN_DIR}

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
	Options FollowSymLinks
	AllowOverride None
	Require all denied
</Directory>

<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

#<Directory /srv/>
#	Options Indexes FollowSymLinks
#	AllowOverride None
#	Require all granted
#</Directory>




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
	Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

Re: where localhost points?

Post by dancer_69 »

I managed to get it work. I don't know why the /var/www doesn't work, but I enabled the "userdir" module of apache2 and I created a "public_html" folder on my user's directory. Then I copied my startpage's files there and using "localhost/~user/" I load the page from there.
User avatar
chazz_tsc
Level 1
Level 1
Posts: 39
Joined: Sun Mar 18, 2012 7:55 pm

Re: where localhost points?

Post by chazz_tsc »

For what it's worth, the key line is:

Code: Select all

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
That says that there are a bunch of files or links in /etc/apache2/sites-enabled, each of which either is a file, or points to a file in /etc/apache2/sites-available, and each of which defines a virtual host; and likely the one that controls the location of the default index page is /etc/apache2/sites-available/000-default.conf .
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

Re: where localhost points?

Post by dancer_69 »

But there aren't any files there except 000-default.conf and default.ssl.conf, and there there is only DocumentRoot /var/www/html. No other files or symlinks. Also in "sites-enabled" folder there is only one symlink which points to 000-default.conf
User avatar
chazz_tsc
Level 1
Level 1
Posts: 39
Joined: Sun Mar 18, 2012 7:55 pm

Re: where localhost points?

Post by chazz_tsc »

How very odd.

Two possibilities: a hidden file .htaccess in /var/www/html that contains a redirect of some sort - a lot of the directives that appear in apache2.conf and 000-default.conf can appear in .htaccess as well; and a DirectoryIndex value in either the conf file or .htaccess that changes the name of the file you're looking for (i.e. "DirectoryIndex myhomepage.html" would make the default page myhomepage.html, and any changes to index.html would only be seen if you explicitly selected localhost/index.html
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

Re: where localhost points?

Post by dancer_69 »

There is no .htaccess file in /var/www or /var/www/html. Also nothing in 000-default.conf. Here its contents:

Code: Select all

<VirtualHost *:80>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EDIT:
maybe is somewhere else this file though, because I tried localhost/index.html and the changes applied.
EDIT2:
Spoke too soon. The changes don't apply in localhost/index.html
User avatar
chazz_tsc
Level 1
Level 1
Posts: 39
Joined: Sun Mar 18, 2012 7:55 pm

Re: where localhost points?

Post by chazz_tsc »

Well, that does explicitly say that the directory used should be /var/www/html. There are a few places I'd look if this was my machine, but I can't really recommend much else... perhaps looking in the /etc/conf-enabled directory for misplaced site configuration files, perhaps checking the logs to see what's actually being served, but it would all sound like flailing around randomly. Best of luck...
dancer_69
Level 1
Level 1
Posts: 38
Joined: Thu May 19, 2011 1:25 pm

Re: where localhost points?

Post by dancer_69 »

Nevermind, I bypass it using userdir option, so it's not a problem any more. Thanks for the help.
Locked

Return to “Networking”