• Digital accessories
  • Server
  • Digital life
  • Privacy policy
  • Contact us
  1. Home
  2. Article
  3. networking - Unable to access Apache webserver from local ...

networking - Unable to access Apache webserver from local ...

Rsdaa 16/11/2021 1015

I am running an Apache web server on a desktop machine running Trisquel 8 (based on Ubuntu). I would like to make the server accessible to other machines/devices on my local network, but I can't figure out how.

When I try to connect from another device, using the local IP address of the Apache server, I get error messages in the browser, such as: in Firefox on a Mac, I get 'Unable to connect. Firefox can't establish a connection to the server at localhost.'. If I try to connect using the DuckDuckGo browser on an Android phone, I get 'Webpage not available. The webpage at http://localhost/ could not be loaded because: net::ERR_CONNECTION_REFUSED'.

One of the answers suggested using nmap to see which ports are open, which returned the following result:

$ nmap [LOCAL IP ADDRESS]Starting Nmap 7.01 ( https://nmap.org ) at 2019-10-12 09:25 EDTNmap scan report for [LOCAL IP ADDRESS]Host is up (0.00013s latency).Not shown: 998 closed portsPORT STATE SERVICE22/tcp openssh80/tcp openhttpNmap done: 1 IP address (1 host up) scanned in 0.09 seconds

So, it shows that port 80 is open for http. It's probably also worth mentioning that I can ping the machine from another on the local network and, as the nmap output shows, I have another port open for ssh. I have been ssh-ing to this machine for several months and that works just fine. For that, I just installed the ssh-server and it pretty much worked out of the box.

So, does that imply that something is wrong with the Apache2 setup (as opposed to iptables/firewall), given that ssh is working with no problems?

Contents of iptables:

$ sudo iptables -LChain INPUT (policy ACCEPT)target prot opt source destination ACCEPT tcp--anywhere anywhere tcp dpt:http ctstate NEW,ESTABLISHEDChain FORWARD (policy ACCEPT)target prot opt source destination Chain OUTPUT (policy ACCEPT)target prot opt source destination

Contents of apache2.conf:

# 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 );# 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## 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/envvarsUser ${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 (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 # container, error messages relating to that virtual host will be# logged here.If you *do* define an error logfile for a # 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/*.loadIncludeOptional mods-enabled/*.conf# Include list of ports to listen onInclude 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.Options FollowSymLinksAllowOverride NoneRequire all deniedAllowOverride NoneRequire all grantedOptions Indexes FollowSymLinksAllowOverride All# Require local# Require ip 192.168.1Require all granted## Options Indexes FollowSymLinks# AllowOverride None# Require all granted## 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.#Require all denied## 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_combinedLogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %O" commonLogFormat "%{Referer}i -> %U" refererLogFormat "%{User-agent}i" agent# Include of directories ignores editors' and dpkg's backup files,# see README.Debian for details.# Include generic snippets of statementsIncludeOptional conf-enabled/*.conf# Include the virtual host configurations:IncludeOptional sites-enabled/*.conf# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I need the AllowOverride All under /var/www because I am trying to run an instance of Wordpress, and it needs to be able to write to the Apache server.

Apache2 is definitely running, as I can access the web content using 'localhost' from a browser on the local machine. Also, systemctl status apache2 shows it is running:

~$ systemctl status apache2● apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Thu 2019-10-10 20:01:44 EDT; 5min ago Docs: man:systemd-sysv-generator(8)Process: 1562 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS) CGroup: /system.slice/apache2.service ├─1621 /usr/sbin/apache2 -k start ├─1624 /usr/sbin/apache2 -k start ├─1625 /usr/sbin/apache2 -k start ├─1626 /usr/sbin/apache2 -k start ├─1627 /usr/sbin/apache2 -k start ├─1628 /usr/sbin/apache2 -k start └─2102 /usr/sbin/apache2 -k startOct 10 20:01:42 lee-Desktop systemd[1]: Starting LSB: Apache2 web server...Oct 10 20:01:42 lee-Desktop apache2[1562]:* Starting Apache httpd web server apache2Oct 10 20:01:43 lee-Desktop apache2[1562]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this messageOct 10 20:01:44 lee-Desktop apache2[1562]:*Oct 10 20:01:44 lee-Desktop systemd[1]: Started LSB: Apache2 web server.

As suggested in the comments, I tried netstat --inet -a | grep apache2, but it returned nothing. Apparently this is unusual if apache2 is running, as it should be listening on port 80. I ran netstat -plunt | grep :80 and got the following output:

$ sudo netstat -plunt | grep :80tcp6 00 :::80 :::*LISTEN1557/apache2

Does this mean Apache is listening, but not hearing anything?

In terms of the virtualhost configs, which were also requested, the only file in /etc/apache2/sites-enabled/ is 000-default.conf, the contents of which is:

# 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.comServerAdmin webmaster@localhostDocumentRoot /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:warnErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${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# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I have also tried running tail -f /var/log/apache2/*.log, but nothing is being printed to the logs when I try to connect from a remote machine.

So, how can I troubleshoot what is blocking the connection? Is there a log anywhere that might enlighten me as to why the connection is being refused, and for what reason?

I tried the suggestions made by Jacob in his answer, but unfortunately it didn't resolve the problem. Any other suggestions or guidance would be greatly appreciated!

PREV: Plex media server FAQ ( Frequently Asked Questions)

NEXT: How to fix common Plex Media Server issues | Windows Central

Popular Articles

Hot Articles
Back to Top