0

We have a websites (foldername /srv/www/vhosts/wp-intranet hosted on a server in our LAN. We need a Vhost for it so that the website is reachable at "http://192.168.20.25/intranet" and/or "http://intranet.mycompany.de"

I followed the instructions in the documentation, but it does not work. This is the VirtualHost config (/etc/apache2/vhost.d/wp-intranet.conf)

<VirtualHost 192.168.20.25>
  ServerName intranet.mycompany.de
  DocumentRoot /srv/www/vhosts/wp-intranet
  ServerAdmin myname@mycompany.de
  ErrorLog /var/log/apache2/intranet.mycompany.de_errorlog
  CustomLog /var/log/apache2/intranet.mycompany.de_customlog common
  <Directory "/srv/www/vhosts/wp-intranet">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

I also added NameVirtualHost *:80 to /etc/apache2/listen.conf.

Then I made a hosts entry on my windows client:

192.168.20.25   intranet.mycompany.de

But if I navigate to intranet.mycompany.de from my windows computer, then the file /srv/www/htdocs/index.html opens.

I also restarted the apache service (service apache2 restart)

I hope someone can point me to the right direction. The documentation is not helpful, I followed each step but it does still not work.

Black
  • 461
  • 1
  • 8
  • 20
  • I am using `Linux version 4.4.132-53-default (geeko@buildhost) (gcc version 4.8.5 (SUSE Linux) ) #1 SMP Wed May 23 06:57:07 UTC 2018 (036cd2f)` – Black Jul 10 '18 at 10:48
  • 2
    The orginal [Apache doc](http://httpd.apache.org/docs/2.4/) is quite good. – Sven Jul 10 '18 at 11:23

2 Answers2

0

In the <VirtualHost> Directive, the syntax is <VirtualHost addr[:port] [addr[:port]] ...>. While a fully qualified domain name for the IP address is supported, it's not recommended. As Apache distinguishes the hostname from the Host: header by ServerName (and optionally with ServerAlias), you don't need it there. Try <VirtualHost *:80>.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • I tried it, but If I open `intranet.mycompany.de` then `/srv/www/htdocs/index.html` still opens. If I open `192.168.20.25/intranet.mycompany.de` then I get `404 site not found`. And yes, I restarted apache2 – Black Jul 10 '18 at 10:47
  • The first match gets used. Add your default virtualhost configuration to your question, and the other virtualhosts, if any. – Esa Jokinen Jul 10 '18 at 11:08
0

I finally solved it. The official documentation is missing important informations and is not up to date.

I had to include my vhost configuration file /etc/apache2/vhost.d/wp-intranet.conf in /etc/apache2/httpd.conf

IncludeOptional /etc/apache2/vhosts.d/wp-intranet.conf

Then I noticed that I am unable to restart the service apache2.

Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

I executed systemctl status apache2.service and got:

● apache2.service - The Apache Webserver
   Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-07-10 12:59:07 CEST; 10s ago
  Process: 2017 ExecStop=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful-stop (code=exited, status=1/FAILURE)
  Process: 7622 ExecReload=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful (code=exited, status=0/SUCCESS)
  Process: 2008 ExecStart=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k start (code=exited, status=1/FAILURE)
 Main PID: 2008 (code=exited, status=1/FAILURE)

Jul 10 12:59:07 intern start_apache2[2008]: AH00526: Syntax error on line 8 of /etc/apache2/vhosts.d/wp-i...onf:
Jul 10 12:59:07 intern start_apache2[2008]: Invalid command 'Order', perhaps misspelled or defined by a m...tion
Jul 10 12:59:07 intern systemd[1]: apache2.service: Main process exited, code=exited, status=1/FAILURE
Jul 10 12:59:07 intern start_apache2[2017]: AH00548: NameVirtualHost has no effect and will be removed in...f:41
Jul 10 12:59:07 intern start_apache2[2017]: AH00526: Syntax error on line 8 of /etc/apache2/vhosts.d/wp-i...onf:
Jul 10 12:59:07 intern start_apache2[2017]: Invalid command 'Order', perhaps misspelled or defined by a m...tion
Jul 10 12:59:07 intern systemd[1]: apache2.service: Control process exited, code=exited status=1
Jul 10 12:59:07 intern systemd[1]: Failed to start The Apache Webserver.
Jul 10 12:59:07 intern systemd[1]: apache2.service: Unit entered failed state.
Jul 10 12:59:07 intern systemd[1]: apache2.service: Failed with result 'exit-code'.
Hint: Some lines were ellipsized, use -l to show in full.

So I figured out that the virtual host configuration from the official documentation has syntax errors. I had to change it to this:

<VirtualHost *:80>
  ServerName intranet.mycompany.de
  DocumentRoot /srv/www/vhosts/wp-intranet
  ServerAdmin edward.black@mycompany.de
  ErrorLog /var/log/apache2/intranet.mycompany.de_errorlog
  CustomLog /var/log/apache2/intranet.mycompany.de_customlog common
  <Directory "/srv/www/vhosts/wp-intranet">
    #Order allow,deny
    AllowOverride All
    #Allow from all
    Require all granted
  </Directory>
</VirtualHost>

Now I was able to restart apache2 and if I navigate to http://intranet.mycompany.de/ then the wordpress site opens!

Black
  • 461
  • 1
  • 8
  • 20
  • Pretty strong accusation. Could you link the "official documentation" that is not up to date and point the errors in it? – Esa Jokinen Jul 14 '18 at 07:23
  • @EsaJokinen, The link is already in my question. Just follow the instructions 1:1 and you will see by yourselv. I even pointed the mistakes out in this answer, please read it again. – Black Jul 14 '18 at 09:32
  • The order there seems at bit confusing, but the solution is explained under heading *Name-Based Virtual Hosts*. Based on the documentation, `/etc/apache2/vhosts.d/*.conf` should be included by default. Is there a chance this could have been changed? The official [Apache HTTP Server Version 2.4 Documentation](https://httpd.apache.org/docs/2.4/) is much more comprehensive. [Configuration Files](https://httpd.apache.org/docs/2.4/configuring.html) explains that the main configuration file is usually called `httpd.conf` and the other configuration files may be added using the `Include` directive. – Esa Jokinen Jul 14 '18 at 09:45
  • I see the problem. Are you really using SuSe Linux Enterprise Server 11, for which the documentation is? SLES11 has Apache 2.2 while the error suggests you have Apache 2.4 that comes with SLES12. The same [Configuring Apache](https://www.suse.com/documentation/sles-12/book_sle_admin/data/sec_apache2_configuration.html) documentation for SLES12 has the *Example 31-4 Basic VirtualHost Configuration* corrected for Apache 2.4. – Esa Jokinen Jul 14 '18 at 09:52
  • How can I look it up? I am using Linux version 4.4.132-53-default (geeko@buildhost) (gcc version 4.8.5 (SUSE Linux) ) #1 SMP Wed May 23 06:57:07 UTC 2018 (036cd2f) – Black Jul 14 '18 at 12:12
  • That's `uname -a`. Try `cat /etc/SuSE-release` to find the SLES version. – Esa Jokinen Jul 14 '18 at 12:53