Running a Docker container on Apache2 - docker

I have a server where I am hosting several apps. They are all accessible on their own subdirectories through the same server name, so my app foo is found at www.servername.com/foo and bar is found at www.servername.com/bar and so on. Most of these apps are Flask apps with the route and the static files configured through apache VirtualHost *:443 to run SSL.
I have been given another Flask app, baz, to run on the server which has been configured to spin up into two Docker containers, one for the app and one for the database. I have managed to adjust my apache .conf file as follows:
<VirtualHost *:443>
ServerName www.servername.com
# some additional config for my other apps, in Directories and static aliases
ProxyPreserveHost On
SSLProxyEngine On
<Proxy *>
Allow from *
</Proxy>
ProxyPass "/baz" "http://<IP address>:5000"
ProxyPassReverse "/baz" "http://<IP address>:5000"
</VirtualHost>
I think the configuration is reaching the running container, because when I go to www.servername.com/baz it redirects to www.servername.com/login. It should redirect to www.servername.com/baz/login, but clearly something hasn't gone right. How can I get the proxy to correctly direct all baz traffic through the /baz subdirectory?
Additionally, I can manually navigate to www.servername.com/baz/login to see the login page for the baz app, but it appears not to have loaded the CSS, so I assume the static files are not being loaded. Do I need to set up an alias for these static files too, like I do with my other non-Docker Flask apps? If so, the standard format that I usually use:
Alias baz/static /path/to/baz/static
is not working. On a whim, I also tried something weirder just to see if it would work:
Alias "baz/static" "http://<IP address>:5000/static"
but this didn't work either. Perhaps it will be fixed by addressing the proxy routing issue above, but how can I make the static files accessible to the baz app?

It sounds like the website that is running under /baz doesn't know that's where it's running and so is rendering URLs under / instead. You have a couple of options:
Use subdomains: baz.servername.com. Then the Flask apps can just use / freely without conflicts.
Make the Flask apps aware of where they're serving, so your Flask app is configured to use /baz to prefix every URL it serves.

Related

How do I deploy to Google Compute Engine using the Ruby stack?

I'm totally lost trying to deploy a demo Rails app to my-app-name.appspot.com. I set up a project in the Developers Console and deployed the Ruby stack on my VM. I would have thought I just need to configure the web server's default site such that the DocumentRoot is the public folder of my Rails app (from /etc/apache2/sites-available/default):
<VirtualHost *:80>
ServerName my-app-name.appspot.com
DocumentRoot /apps/my-app-name/public
<Directory /apps/my-app-name/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Since I'm aiming for the my-app-name.appspot.com space and not using a separate domain, I'm guessing the ServerName and ServerAlias settings are not needed in this case. Now when I visit my target appspot.com address I get a 404 error:
Not Found - The requested URL / was not found on this server.
The logs show that Phusion Passenger is in fact listening to requests. And when I visit the numbered IP address for my project I still get Apache's default index page. Obviously there's a crucial part of the picture I'm not seeing, so any help is greatly appreciated.
Thanks to the posters who commented, I now understand that I was barking up the wrong tree. The appspot.com domain is not compatible with compute engine; I will have to access my project via the IP address.
Also, since I was only trying to put up a test app as proof of concept, I needed to set the Rails environment to development. I was frustrated until I found these instructions (Step 6): https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-apache-on-ubuntu-14-04
Detailed instructions how to deploy Ruby on Rails on Google Compute Engine:
http://startup-with-gae.blogspot.com/2015/08/how-to-deploy-ruby-on-rails-application.html

What is the difference between setting up mod-mono virtual hosts via webapp file versus apache site configuration?

I'm using mod-mono for deploying an asp.net mvc application on Ubuntu Server 10.04. The following packages were installed: mono-apache-server4 libapache2-mod-mono apache2.
There are several blogs that configure mod-mono virtual hosts via the sites-available Apache configuration. For example, I could modify /etc/apache2/sites-available/default configuration like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
MonoApplications "/:/var/www"
MonoServerPath /usr/bin/mod-mono-server4
... more default configuration
But then there are also sites that advise to use an webapp file for mod-mono virtual host configuration. For example, I could modify /etc/mono-server4/debian.webapp like this:
<apps>
<web-application>
<name>default</name>
<vpath>/</vpath>
<path>/var/www/</path>
<vhost>127.0.0.1</vhost>
</web-application>
</apps>
Both approaches however need an apache site SetHandler mono configuration setting.
The only difference I noticed is that for sites configuration I have to explicitly define mod-mono-server4 (otherwise the system is trying to start a server2 instance which is not installed). When configured via sites configuration it also seems that there is an additional mono_server process spawned.
I guess I should go with the webapp option, but are there any "big" differences between this two approaches? Is webapp configuration distribution specific or why are there two options anyway?
Webapp config file approach can also be used with stand-alone XSP4, without the need of apache.
For example, you can run:
xsp4 --appconfigfile etc/mono-server4/debian.webapp
And you'll get XSP4 working with your webapp config file.

Configuring an EC2 instance as a space to serve up all my Rails\WordPress projects

How do I configure an Amazon EC2 instance as a personal space to serve up whatever Ruby on Rails or WordPress projects I want, with their own domains? As a developer, I've found surprisingly little information on how to create your own "bucket" for all your various web-based projects.
It's surprisingly easy to get started but there are dozens of different ways to go about it. For the sake of giving you relevant resources I'm going to make a few assumptions about your setup and try to paint with broad strokes:
You're running a Debian-based Linux distribution (Ubuntu is popular and has a great community)
You're running a LAMP (Linux, Apache, MySQL, and PHP) stack (see Installing LAMP Server in the Ubuntu documentation).
You'll be deploying your sites to the default server location of /var/www
The first thing you'll want to do is read up on virtual hosts (vhosts). A common pattern is to put virtual hosts' web roots in subdirectories of /var/www/vhosts/ (e.g. /var/www/vhosts/example.com/), though these can technically live anywhere on the server.
After creating your document roots you'll give each site each a virtual host file in /etc/apache2/sites-available that looks (at a very high/rudimentary level) something like this:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/vhosts/example.com/
</VirtualHost>
This tells Apache to listen for requests for www.example.com and route them to /var/www/vhosts/example.com. There are a whole mess of Apache vhost configuration options, I'd recommend a Google search for some more specific examples though looking at the 000-default vhost that comes bundled with Apache on Ubuntu is a good place to start.
When you're ready to activate the vhost you'll need to enable the virtual host and reload/restart Apache:
$: a2ensite {your vhost file name} # Creates a symlink to this vhost file in /etc/apache2/sites-enabled/
$: service apache2 restart # restart Apache
Since you want to point different domains to your projects you'll simply need to create a DNS record (A-records will be the easiest unless you're dealing with all sorts of shifting IP addresses) and point it to the IP address of your server. Apache will route the domain to the appropriate virtual host.
For Rails projects the web root should be the public/ directory, so your DocumentRoot directive will be DocumentRoot /var/www/vhosts/example.com/public. You'll also need to be running a Ruby-compatible server for Rails apps, Phusion Passenger, Thin, and Unicorn are all pretty popular.

Multiple sites in multiple projects on the same rails server

I've searched the web, but I can only find information on sharing code between multiple sites and on separating the database to isolated models. This is not what I want.
I want to run a single rails server, with a single DNS address and a single port - http://myportal.com - that will handle several other sites - http://myportal.com/site1, http://myportal.com/site2 etc.
I want each site to have it's own folder(and SCM repository), it's own database, it's own routing - it's own everything. That is - I want to be able to develop each site as a standalone - that means I need to be able to run site1 site as http://localhost:3000 and not http://localhost:3000/site1.
On the server, the root site(the one that responds to the http://myportal.com address should be the one I run the server from, and it should know the absolute paths of the other sites(which will be in different directories on the server, not in child directories of the root site) and provide routing information for them - but it should also chain to the other sites routes.rb files. That means that if I go to address http://myportal.com/site1/books/ the root site should handle http://myportal.com/site1, and site1 should handle /books/. The root site should not need to know about the other sites' internal routing structures.
Is this possible? Right now I'm running the rails server that comes with the gem(rails server from the command line) on a Windows Server 2008 server, but I'm willing to install another server if that's what needed to accomplish the goal I described.
Thanks in advance!
You should be able to do this with Apache or nginx and possibly IIS if configured correctly. I'm most familiar with Apache and the flexible mod_rewrite and mod_proxy components that can facilitate this.
The idea is you rewrite http://example.com/ to be http://example.com:3000/ and http://example.com/site2 as http://example.com:3001/site2 and so forth.
It's also possible to do this with Passenger and some clever use of the VirtualHost directive, but you may have to fiddle to get a configuration that works for you. Remember that rewriting the headers to route internally has no effect on the resulting HTML your servers emit.
Create a symlink:
cd ~/Sites
ln -s /Users/hg/Developer/Rails/railsproj1/public ./railsproj1
modify apache config file
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/hg/Sites
<Directory /Users/hg/Sites>
AllowOverride All
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
</Directory>
RailsBaseURI /railsproj1
RailsEnv development
</VirtualHost>
Answer source: http://collab.stat.ucla.edu/users/jose/weblog/9e335/

How to configure apache to serve both RoR and Flask on the same machine?

I have a dedicated machine I use for testing. At the moment it's running a Rails (2.3) app over Apache and Passenger. I would also like to simultaneously serve a Flask application using the same machine and a different url if possible. Here's what I currently have for my httpd.conf file:
<VirtualHost *:80>
DocumentRoot /path/to/rails-app/public
PassengerDefaultUser railsuser
RailsEnv testing
# .. some misc apache config
</VirtualHost>
How should I modify it to serve two different urls (on a local network) with one serving the Rails app and the other serving Flask? Thanks.
In your OP, you're setting the handling for the default url.
For your second virtual web server, just use a specific host name in the config that is a second host name for the same machine. This is called "name-based" virtual hosting. See wikipedia.
Remember that multiple hostnames can resolve to the same IP address.
You can use the full dns system if you want, just specify your local network address (192.168.xxx) -- the url will not work for machines not on your local network.
More info will be available at the webmasters SO site.
A post with instructions

Resources