So far, we have used Rails to develop, test and demonstrate a web application. Since the web browser was running on the same computer as Rails and its web server, we could simply access the web application using localhost as part of the URL. Here, however, we discuss options for accessing the web application over the internet. The following sections present options ranging from worst performance (but simplest) to the best performance.
If we don't care at all about performance, we can simply run the server in the default development environment. If the computer is on the internet and has an IP number (example: 67.186.79.78), the reviews web application could be accessed with this URL:
http://67.186.79.78:3000/reviews
If your computer has a registered host name (example: it232.com) through a Domain Name Server (DNS), you can access the web application accordingly:
http://it232.com:3000/reviews
Finally, if you start the server with this option:
rails server -p 80
The server will run on port 80, which is the default port for a URL. This way, the URL does not need to specify the port number:
http://it232.com/reviews
Note that some internet service providers block port 80, which will prevent you from running the server on this port.
Performance is greatly increased by running a Rails application in the production environment. Here are some important differences from the development environment:
All but the last item improves the performance of the web application.
In order to run your web application in the production environment, you need to do the following steps:
rake db:schema:load RAILS_ENV=production
rails console production
rails server -e production -p 80
Assuming you have a recent installation of Rails, your Rails application uses Mongrel as the web server. Mongrel passes all web requests to your Rails application.
This diagram illustrates this simple configuration, where Mongrel is the only web server operating in this deployement:
Mongrel is not intended as an efficient server for static pages. A common deployment strategy uses a production-quality web server (e.g. Apache) on the front-end:
A production-quality server such as Apache is usually multi-threaded and can handle multiple requests simultaneously. Since Mongrel and the rail application is single-threaded, handling multiple requests simultaneously involves creating multiple instances of Mongrel running the rails application:
Servers such as Apache can balance the load of requests among the multiple instances of back-end servers. Phusion Passenger (installed on topaz) uses this approach.
Unless your application will only have a few users accessing the application at a time, you will probably want to use a production-quality database such as MySQL, which can better handle multiple requests at a time. You will either need to create a database in MySQL or ask a system administrator to do it for you. With the database name, user name and password, you can then edit the config/database.yml file to configure for MySQL in the production environment.