Using Elastic Beanstalk from Amazon Web Services is a create way to deploy large projects and be ready for a gain in visitors. Because I have a few projects which are too small to deploy each project as its own Elastic Beanstalk application I looked for a way to deploy several projects with multiple Domains into one AWS EB application.
In the past the only way to configure application environments was to use customized AMIs. This would mean that I can not update my application to newer Amazon AMIs. So I would have to update my AMI regularly on my own.
A new and better way is to use the new configuration files. After deploying an application the configuration files, stored in the folder .ebextensions on the root directory of the applichation, are processed. All configuration files must end with ‚.config‘.
The Elastic Beanstalk uses regular EC2 instances with an apache webserver. So I used the configuration files to create an file inside the apache folder to tell the webserver how to handle multiple domains. The deployed PHP application is stored inside the /var/www/html folder.
Here is the configuration file. I saved it under .ebextensions/vhost.config
files: "/etc/httpd/conf.d/vhost.conf": mode: "000644" owner: root group: root encoding: plain content: | NameVirtualHost *:80 <VirtualHost *:80> ServerName www.projekt1.de ServerAlias projekt1.de DocumentRoot /var/www/html/projekt1/ </VirtualHost> <VirtualHost *:80> ServerName static.projekt1.de DocumentRoot /var/www/html/static/ </VirtualHost>
The lines after the content entry were copied into a new file /etc/httpd/conf.d/vhost.conf. The webserver reads this file on startup an creates new vhosts with different root folders. All requests for www.projekt1.de or projekt1.de use /var/www/html/projekt1/ als document root. Requests to static.projekt1.de use folder static inside the application as document root.
For detailed information on how to configure multiple domains in apache read the VirtualHost Examples from the apache project page.
If you have any questions, problems or suggestions please write a comment on this post.