0

I have an Elastic Beanstalk server which I am using for my employer's main site, example.com and they want me to host one of their ancillary sites on it: go.example.com.

So I just created a new ebextension config to create a second vhost. The problem I found is that Apache (HTTPD) only wants to use the first vhost entry.

Here are my vhosts:

 # I have Apache listening on port 8080 because I have varnish in front of my sites.
    <VirtualHost *:8080>

        ServerName      example.com
        ServerAlias     www.example.com
        ServerAdmin     webmaster@example.com

        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^example.com
        RewriteRule ^(.*)$ http://www.example.com%{REQUEST_URI} [R=301,L]

        DocumentRoot "/var/app/current/httpdocs"

        <Directory "/var/app/current">
            AllowOverride All
            Require all granted
        </Directory>

        <Directory "/var/app/current/cgi-bin">
            AllowOverride All
            Options None
            Require all granted
        </Directory>

        <Directory "/var/app/current/httpdocs">
            Options FollowSymLinks
            AllowOverride All
            DirectoryIndex index.html index.php
            Require all granted
        </Directory>

    </VirtualHost>
    #go.example.com
    <VirtualHost *:8080>

      ServerName      go.example.com
      ServerAlias     staging.go.example.com
      ServerAdmin     webmaster@example.com

      DocumentRoot    /var/www/go.example.com/httpdocs

      <Directory "/var/www/go.example.com">
          AllowOverride All
          Require all granted
      </Directory>

      <Directory "/var/www/go.example.com/httpdocs">
          Options FollowSymLinks
          AllowOverride All
          DirectoryIndex index.html index.php
          Require all granted
      </Directory>

So the server will always listen for example.com, and with the above vhost order example.com will serve /var/app/current/httpdocs while go.example.com is just a blank page.

If I swap the vhost order, so go.example.com is first, then example.com serves /var/www/go.example.com/httpdocs. And go.example.com is still a blank page.

Nothing is really jumping out at me, and I dont have this problem is I build a regular ol' EC2.

Patrick Mevzek
  • 9,921
  • 7
  • 32
  • 43
rugbert
  • 83
  • 2
  • 10

2 Answers2

1

Change:

  <VirtualHost *:8080>

To:

  NameVirtualHost *
  <VirtualHost *:8080>

See the explanation here: https://serverfault.com/a/497075/164840

Marcel
  • 1,730
  • 10
  • 15
  • 2
    This makes no sense. `NameVirtualHost` is not a directive you can put in `<>`. And if you change `VirtualHost *:8080` to `VirtualHost *` then you may not be listening correctly on 8080 anymore. Also `NameVirtualHost` is not needed anymore starting with Apache 2.3.11 – Patrick Mevzek Nov 16 '18 at 15:31
  • Ah, yeah, sorry, too long without doing anything on Apache anymore. – Marcel Nov 16 '18 at 17:04
0

It looks as though your missing:

  </VirtualHost>

at the end of the file you pasted to close that vhost off. Also make sure that your sites-enabled has info on your new vhost in it.