Apache Virtual Host - Could not resolve host name

Hi everybody,

as a small web developer I used Xampp on Windows 8.1 until it crumbled. The prospect to install Windows 10 drove me to Linux. I settled for openSuse Leaf 15.1 and am very happy with the Gnome desktop.

My goal is to run a local webserver to serve local domains for web development like it was on Windows.
After an unpleasant experience with an one-click installtion from the web I used Yast for the webserver.

Installed **patterns-server-lamp_server **20180302-lp151.5.1

Created working directories and put links in the webserver htdocs folder

sudo ln -s /home/mife/www/htdocs/domain.local /srv/www/htdocs/domain.local

In Yast HttpServer de-/actived some modules and added two virtual hosts like domain.local

localhost is reachable, but not domain.local:

Chrome 77.0.3865.90 shows for http://domain.local that it can not find the server ip address
ERR_NAME_NOT_RESOLVED

For days I’m searching and reading but couldn’t come up with a solution.

Do I need to use Yast Networksettings Hostname/DNS or Routing?

Looking forward to any hint
mife

Host/domainnames must be resolvable to IP addresses, else nobody can find the system. Resolving is done using a combination of /etc/hosts (often for local, on the LAN, available systems) and DNS servers (for everything on the internet).
the name localhost is normaly defined in /etc/hosts as 127.0.0.1, so that can be resolved.

I assume local.domain is defined nowhere. I do not know why you started usng that strange combination. but you could define it also in /etc/hosts (either by editing or using YaST).

@mife:

You may have to manually setup the Apache configuration – beware, subsequent usage of the YaST module may well overwrite your changes …

  • Take a look in /etc/apache2/httpd.conf – it points to “*.conf” files located in /etc/apache2/vhosts.d/conf.d/ and, it points to <http://httpd.apache.org/docs/2.4/vhosts/> – there’s a .conf template in /etc/apache2/vhosts.d/.
  • But, that template is not the same as what things such as Drupal do …
  • Be aware that, due to the changes YaST makes to the Apache configuration files, you may have to retrieve the “apache2” RPM package and then open it with “ark” to examine the original fully commented Apache configuration files.
  • BTW, WordPress does something totally different – it doesn’t run as a Virtual Host and, it drops a “wordpress.conf” into /etc/apache2/conf.d/ …

[HR][/HR]As an example of how Virtual Hosts are setup, the ‘drupal8.conf’ located in /etc/apache2/vhosts.d/conf.d/ is as follows:


# Example configuration for a drupal8 repository
#
# As default server
# put the string DRUPAL8 in /etc/sysconfig/apache2 APACHE_SERVER_FLAGS
# to enable the URL
# http://localhost/drupal8
#
# As vhost
# If you want to use drupal8 in one vhost add
# Include /etc/apache2/vhosts.d/conf.d/drupal8.conf
# to the vhost in the vhost.conf file
# put the string DRUPAL8VHOST in /etc/sysconfig/apache2 APACHE_SERVER_FLAGS
# to enable the URL
# http://vhost/drupal8
<IfDefine DRUPAL8VHOST>

        # apache can serve the static files directly
        Alias /drupal8 "/srv/www/drupal8/"
        <Directory /srv/www/drupal8/>
                        Options FollowSymlinks
                        AllowOverride All
                        Require all granted
        </Directory>

</IfDefine>

As a furthe example, for Typo3 it looks like this:


# Example configuration for a typo3 repository
#
# As default server
# put the string TYPO3 in /etc/sysconfig/apache2 APACHE_SERVER_FLAGS
# to enable the URL
# http://localhost/typo3
#
# As vhost
# If you want to use typo3 in one vhost add
# Include /etc/apache2/vhosts.d/conf.d/typo3.conf
# to the vhost in the vhost.conf file
# put the string TYPO3VHOST in /etc/sysconfig/apache2 APACHE_SERVER_FLAGS
# to enable the URL
# http://vhost/typo3
<IfDefine TYPO3VHOST>

        # apache can serve the static files directly
        Alias /typo3 "/srv/www/htdocs/"
        <Directory /srv/www/htdocs/>
                        Options FollowSymlinks
                        AllowOverride All
                        Require all granted
        </Directory>

</IfDefine>

What combination do you mean?

@dcurtisfra

in my system its in

/etc/apache2/vhosts.d/ip-based_vhosts.conf

<VirtualHost domain.local:80>
 DocumentRoot /srv/www/htdocs/domain.local
 ServerName domain.local
 ServerAdmin postmaster@localhost
 <Directory /srv/www/htdocs/domain.local>
  AllowOverride All
  Require all granted
  Options Indexes FollowSymLinks ExecCGI Includes
 </Directory>
</VirtualHost>

local.domain or domain.local, it is all fantasy to me.

In Windows it was in
/etc/hosts

127.0.0.1 domain.local
127.0.0.1 anotherdomain.local

That told the browser to use the IP to respond a request for the corresponding domain name.
This is exactly what I try to achieve with Yast.

Is it even possible?

If the answer is YES I would love to know where to enter the data.

Maybe it sounds crazy to some of you, but I really would prefer to use Yast for the configuration.

It is just a place-holder for real web domain.
Assuming a client wants me to build company.com then I set up **company.local **in my local web environment.

You never looked at what YaST offers you?

YaST > Network Services > Hostnames. Not very surprising. And then you have to type the same things as when you use your favorite editor. I love YaST, but in this case there is not much gain in using it. In any case, I do not understand why you can not find that.

Although you can set up your Apache manually, I’d probably recommend instead using the YaST http server module, then tinker with the configuration as needed.

The LEAP documentation for Apache is here

https://doc.opensuse.org/documentation/leap/reference/html/book.opensuse.reference/cha.apache2.html

It sounds like you need name resolution for your virtual websites for development, and maybe don’t need to serve your websites in your LAN, so configuring entries in your hosts file should be sufficient, it’s nearly exactly the same as the file you configured in your MSWindows

/etc/hosts

Be aware that some complex sub-websites will use an Apache re-write header module to expose a TLD instead of a sub-domain to the User…

On the topic of “domain.local” or “local.domain” my personal SOP is to avoid using any words or phrases that might conceivably be used as a placeholder by technologies… So for instance there is the infamous “.local” namespace used by Avahi. If you have Avahi services running in your LAN, “.local” names can be a problem.

HTH,
TSU

Thank you Henk, that was exactly the missing piece.

Because of the german language I choose for the UI.
In german it reads “Rechnername” which translates to computer name.

Following the discussion what tld to choose for local domains it seems there’s no solution without advocats against it. I’ve read that .local was owned by M$ and someone pointed at their own documentation where it was implied that it’s ok to use .local for local domains.

Right now it works for me.

Thanks to everybody contributing here’s the

Solution

Define your local hosts with Yast

Yast > Network Services > Hostnames
in german it’s Yast > Netzwerkdienste > Rechnername

[size=1]# default
127.0.0.1 localhost

local domain

127.0.0.2 domain.local
[size=1]127.0.0.3 anotherdomain.local
[/size]

TLD .local for local domains

Seems that Suse is ok with that:

The .local top level domain is treated as link-local domain by the resolver. DNS requests are send as multicast DNS requests instead of normal DNS requests.

https://doc.opensuse.org/documentation/leap/reference/html/book.opensuse.reference/cha.network.html
[/size]

P.S. I would like to mark the thread as solved. The search gave me a couple of threads for that topic. The answers ranged from “you can’t’” to “edit tags and add solved” which I can not find.
But maybe the title change of this post does the trick.

P.S. I would like to mark the thread as solved. The search gave me a couple of threads for that topic. The answers ranged from “you can’t’” to “edit tags and add solved” which I can not find.
But maybe the title change of this post does the trick.

We don’t have an option to mark threads as solved, but this one works as well.

I don’t agree that setting the $HOSTNAME in YaST (which is accurately also referred to as the Computer Name) should solve your problem… Unless that is the only virtual website you set up. The whole point of identifying websites by their host headers (which is not the same as the $HOSTNAME), you will find the resolution method you’ve configured will not work for additional sites… And, that is the whole point of this configuration, to enable more than one website to share using the same IP address.

You instead need to configure the website properly with its Host Headers, and then provide hostname resolution (note that hostname resolution only refers to the hosts/DNS name resolution system as opposed to NetBIOS name resolution and not specifically $HOSTNAME) by any means. I don’t know where your error is because it could be anything and your current faulty setup would still work… again, only because it’s the first and likely only website on your system.

To minimize your errors, you should or could follow my recommendation… The YaST http-server module will set up your website’s host headers properly so that you should only then need to configure your /etc/hosts file to set up your system correctly. It’s well known that the more handcrafted configuration, the more exposure to error.

IMO,
TSU

The problem won’t affect everyone.
As I noted, it’s a well known problem when running Avahi services on your network which not everyone does.
You can do an Internet search to verify the problem.
If you never run into a problem, that’s OK but in general it’s a problem to be avoided so can’t be recommended… because choosing a proper Domain name in the beginning is the easiest way to fix a problem… Or, you may never have had to go in months or years later and had to change a Domain name. It’s really difficult, particularly if it’s tied into your network security (eg LDAP or AD)… You end up doing deep surgery on the technology no one ever wants to touch voluntarily.

TSU

I’m missing an Apache “Alias” entry:

  Alias /domain.local "/srv/www/htdocs/domain.local/"

There’s also a syntax error – missing terminating slash: “/”:

  <Directory /srv/www/htdocs/domain.local/>

[HR][/HR]You’re on Linux, which is a UNIX®, «as is the product from Cupertino», and, it’s not the same as that product from Redmond …

  • With UNIX®, syntax matters …

[HR][/HR]By the way, by using openSUSE I “buy local” and, the commercial fonts I use are also from a foundry not so far from where I’m sitting … :wink: