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/
Related
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.
I was just wondering how you would do this for a domain name?
name.example.com
How would you make entering a url like above, direct to somewhere on a server?
example:
forum.example.com would take you to a forum on the server
So, this looks like more of an Apache question than a DNS question.
For DNS, you need to add the proper IP address and subdomain to your DNS entry on your authoritative DNS server.
www A AAA.XXX.YYY.ZZZ
forum A AAA.XXX.YYY.ZZZ
These can be different servers, if you're looking to host forum on a different server than your www page. For more information on DNS configuration files (depending on how you're doing your DNS configuration - although the syntax is reasonably universal) - see here.
I'm assuming, though, you want to host both www and forum on the same server, but serve from different file directories for each. For Apache, you just create a virtual hosts like so:
<VirtualHost *:80>
ServerName forum.example.com
DocumentRoot "/var/www/forum/"
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot "/var/www/html/"
</VirtualHost>
This allows Apache to serve out of different directories, based on the incoming server request. For more information on name-based VirtualHosts, see here.
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
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.
I am using Ruby on Rails 3.1 and I have an application running at the www.mywebsitename.com domain. For improvement reasons I would like to run my application at the www.uk.mywebsitename.com subdomain (BTW: at the www.mywebsitename.com domain I will run a RoR application to redirect users to the proper subdomain).
I do not need geocoding or similar. Simply, I would like to know how to run my application on the www.uk.mywebsitename.com Web address (I am planning to add as subdomain other/similar RoR applications like www.de.mywebsitename.com and www.it.mywebsitename.com, each working with a separate database): what I have to care/do? what do you advice about?
P.S.: My server is running Linux Ubuntu and Apache. I deploy with the Capistrano gem.
It seems like you're looking for how to make apache vhosts, since that's basically what they do.
I assume you're using phusion passenger, and in that case you should already have one vhost (or at least a default site in /etc/apache/sites-available (or something similar, it might be apache2, I'm not entirely sure).
What you basically need to do to get multiple rails applications working is to set up one vhost for each rails application and set the proper ServerName and DocumentRoot for each vhost.
It might look something like this for you uk site:
<VirtualHost *:80>
ServerName www.uk.mywebsitename.com
DocumentRoot /path/to/where/your/uk/site/is/deployed/current/public
<Directory /path/to/where/your/uk/site/is/deployed/current/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
How to setup vhosts for passenger is documented in the passenger documentation.