1

My goal: Run Apache on Ubuntu. Use it to debug web sites before I put the HTML on shared hosting.

I hope: Every time Firefox runs, it will render a web site the same.

I get: Firefox doesn't reliably render my simple web site.

I'm calling my simple web site win.com. My test URLs are each of the four win.com URLs listed in the hosts file listing below.

Example: I start Firefox in Ubuntu. My test URL was active during shutdown; Firefox remembers it and processes it. One of three results occurs:

  • My web site paints correctly.
  • Firefox tells me: "Unable to connect | An error occurred during a connection to localhost."
  • Firefox tells me: "Not Found | The requested URL was not found on this server."

I close Firefox. I start Firefox. One of the three above results occurs. If this request for rendering is within a Firefox session in which another request has occurred, the two results are the same. Refresh has the same result.

Maybe the problem is my computing stack. I'm using a Win10 computer. On it, I run VMWare Workstation 16 Player. In it, I run Ubuntu. All three are current.

I assess risk from the web site as low.

  • It's 56 lines of simple and raw HTML with two images. It has run flawlessly in a shared hosting environment for a couple of years without modification.

  • I have a copy of the site in the Windows environment. The site works reliably in the Windows Firefox using a URL of the form file:///C/.../index.html.

I haven't done much with the similar URL in the Ubuntu environment (file:///var/www/html/win.com/index.html). For this write-up, I tried it several times with identical results.

I no longer have access to a shared hosting environment.

The Ubuntu host file (/etc/hosts), in relevant detail, is

127.0.0.1   localhost
127.0.0.1   https://localhost

127.0.0.1 win.com 127.0.0.1 https://win.com 127.0.0.1 localhost/win.com 127.0.0.1 https://localhost/win.com

I inform Apache about the site via /etc/apache2/sites-enabled/win.com.conf:

<VirtualHost *:80>
    ServerAdmin ewin@twc.com
    DocumentRoot /var/www/html
    ServerName win.com
    ServerAlias *.win.com
DirectoryIndex index.html

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

&lt;Directory /var/www/html&gt;
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
&lt;/Directory&gt;

</VirtualHost>

<VirtualHost :443> ServerAdmin ewin@twc.com DocumentRoot /var/www/html ServerName win.com ServerAlias .win.com

DirectoryIndex index.html

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

&lt;Directory /var/www/html/win.com/&gt;
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
&lt;/Directory&gt;

SSLEngine on
SSLCertificateFile /etc/ssl/certs/self-signed-win.com.crt
SSLCertificateKeyFile /etc/ssl/private/self-signed-win.com.key

</VirtualHost>

I regularly monitor folder /var/log/apache2/ (APACHE_LOG_DIR). Files access.log, error.log, access-win.com.log, and error-win.com.log are regularly zero-length.

This question is as specific as I know to make it. If I were in a group of programmers, I would seek help among them with less effort than posing this question. I'm not in a group.

I've looked for related questions here. None found.

I am stronger in Windows than in Ubuntu or Apache. This exercise is helping me learn the latter two.

I read well. If you know where the answer is, please feel free to point me to that location and I'll happily find the answer there. Maybe limit the breadth of searching I need to do by giving me a search term or subject area!

I'm not getting help from documentation because I don't know the nature of the error enough to read about it.

If this question is inappropriate for this site, I'm happy to remove the question on request with no (other) questions asked.

I'll appreciate all help offered. I won't resent anyone skipping this question.

BaldEagle
  • 113
  • 1
    One thing to look at is the /etc/hosts definition. If you do not have corresponding IPv6 entries for each of the IPv4 records, weirdness and overall sluggish lookups can occur. Add some ::1 records (and ditch the lines containing the protocol, as it’s irrelevant) and you may be golden – matigo Oct 25 '22 at 23:27

1 Answers1

1

Your /etc/hosts file is broken. There must be only host names in this file, no url, no /. Just names. You need to list all the names you are going to use. Also, keep all default IPV4 and IPV6 lines. These make ubuntu work smoothly. Example:

127.0.0.1 localhost
127.0.1.1 yourpcname

win.com

127.0.0.1 win.com foo.win.com bar.win.com

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters

With that, you'll be able to access http://win.com, http://foo.win.com, http://bar.win.com. Of course, you may also access using https, ie https://win.com provided the apache config is correct.

Now the errors :

  • Firefox tells me: "Unable to connect | An error occurred during a connection to localhost."
    The apache 2 server is not running. start apache with something like sudo systemctl restart apache2. If it does not start, there is an error in the configuration. In this case, run sudo apache2ctl configtest. This will tell you where the error is.
  • Firefox tells me: "Not Found | The requested URL was not found on this server.".
    This is the apache server answering your query. You asked for, say http://win.com/foo/bar.html but apache2 could not map that URL to a file. Check /var/log/apache2/access.log. Your documentroot is /var/www/html so, to satisfy http://win.com/foo/bar.html, apache2 will search the file /var/www/html/foo/bar.html. If that file does not exist, it will return the «404 Not found» error. Please note that, with your current config:
        ServerName win.com
        ServerAlias *.win.com
    
    the queries for http://win.com/foo/bar.html and http://foo.win.com/foo/bar.html will map to the same file /var/www/html/foo/bar.html. If you need different folders for different names, then you must use different VirtualHost sections, each with its own ServerName and its own documentroot.
exore
  • 997
  • 6
  • 10
  • Well done with this answer. And prompt. I took time applying your information before crediting this as the full answer. I'm done. Great work. – BaldEagle Nov 21 '22 at 02:12