4

I'm trying to setup an application within Amazon's Elastic Beanstalk, and I'd like to use a subdomain for part of the application. Ideally, that subdomain would be mapped to a folder within the document root (ie: http://test.mydomain.com pulls the sources from /var/www/html/test). I could setup another alias record in Route 53 for the subdomain, but how do I map Apache?

The only way I can think to accomplish this is to SSH in to a server directly, add the VirtualHost entry to my httpd.conf, then roll that server into an AMI and redeploy across EBS. Is that the only option? (it seems like there must be an easier way)

Thanks!

0

This is not possible with Elastic Beanstalk (at least not without really misusing it). Elastic Beanstalk is "fire and forget" type of PaaS solution aimed at simple deployments. If you really need this type of functionality, look into CloudFormation which lets you get much more granular with your instance configurations.

17

Try the following link.

Add a config file in your root inside .ebextensions directory.

Then add this.

files:
  "/etc/httpd/conf.d/vhost.conf":
    mode: "000644"
    owner: root
    group: root
    encoding: plain
    content: |
      NameVirtualHost *:80

      <VirtualHost *:80>
        DocumentRoot "/var/app/current/"
         <Directory "/var/app/current/">
          Options Indexes FollowSymLinks MultiViews
          AllowOverride All
          Require all granted
         </Directory>
      </VirtualHost>

      <VirtualHost *:80>
       ServerName your-custom-domain-here.com
       DocumentRoot "/var/app/current/your-new-webroot"
        <Directory "/var/app/current/your-new-webroot">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Require all granted
        </Directory>
      </VirtualHost> 

More info here:

http://blog.celingest.com/en/2013/04/05/elastic-beanstalk-cloudflare-newrelic-virtualhost-2/

  • 1
    this is the correct answer... – contool May 12 '16 at 17:49
  • Thanks! It worked like a charm – phoenix Feb 22 at 19:09
0

For the people who scroll after right answer here is the solution.

$ cd etc/httpd/conf/
$ sudo nano httpd.conf

Add these lines at the end

<VirtualHost *:80>
    ServerAlias yourstaticsubdomain.example.com
    DocumentRoot "/var/www/html/static"
    <Directory "/var/www/html/static">
    AllowOverride All
    Require all Granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerAlias www.example.com
    DocumentRoot "/var/www/html"
    <Directory "/var/www/html">
    AllowOverride All
    Require all Granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerAlias *.example.com
    DocumentRoot "/var/www/html/wildcard"
    <Directory "/var/www/html/wildcard">
    AllowOverride All
    Require all Granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerName waybill.work
    DocumentRoot "/var/www/html"
    <Directory "/var/www/html">
    AllowOverride All
    Require all Granted
    </Directory>
</VirtualHost>

Note: Appache version less that 2.4 add this line

NameVirtualHost *:80 

before above codes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.