Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Real-Life Rails: Develop with NetBeans, Deploy on Linux : Page 4

Find out how to leverage the Ruby and Rails support in NetBeans 6.0, and then learn some techniques for deploying Rails applications on a Linux server efficiently.


advertisement
Installing and Configuring the nginx Proxy and Web Server
On your server, download the latest stable version of nginx and install it:

cd nginx-0.5.35 ./configure make sudo make install

This installs nginx in /usr/local/nginx, and you need to edit the file /usr/local/nginx/conf/nginx.conf to look like this:



worker_processes 3; error_log logs/error.log notice; error_log logs/warning.log warning; pid logs/nginx.pid; events { worker_connections 1024; } http { include conf/mime.types; default_type application/octet-stream; tcp_nopush on; keepalive_timeout 65; tcp_nodelay on; upstream mongrel { server 127.0.0.1:3001; server 127.0.0.1:3002; server 127.0.0.1:3003; } gzip on; gzip_min_length 1100; gzip_buffers 4 8k; gzip_types text/plain; server { listen 80; server_name cookingspace.com; root /var/mongrel/cookingspace/public; access_log off; rewrite_log on; location / { proxy_pass http://mongrel; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }

To test, make sure that your Mongrel cluster has started and run nginx manually:

cd /usr/local/nginx/ sbin/nginx -c conf/nginx.conf

Starting Your Mongrel Cluster and Nginx Automatically
This was a tough section for me to write because different Linux distributions have slightly different tools for managing processes at startup. That said, even though it is a little "old school," I think that most Linux distributions (and also FreeBSD, etc.) support putting startup commands in /etc/rc.local. So that is what I will show here. I tested this on only one Linux server:

# I made sure that /usr/local installs are visible: export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH export PATH=$PATH:/usr/local/bin # start memcached using a non-privileged account: /usr/local/bin/memcached -d -m 16384 -l 127.0.0.1 -p 11211 -u cookingspace >
/home/cookingspace/memcached.log & # start the mongrel cluster and nginx using non-privileged accounts: (cd /var/mongrel/cookingspace/ ; su cookingspace -m -c "nohup
/usr/local/bin/mongrel_rails cluster::restart > /home/cookingspace/mongrel_rails.log &" ) (cd /usr/local/nginx/ ; sbin/nginx -c conf/nginx.conf) # note: nginx spawns worker processes using a non-privileged account.

This is a little simplistic, but it has the advantage of likely working on most systems.

A Time-saver
After working with server-side Java for over 10 years, I find writing Rails applications to be a lot of fun. It seems to take much less time to get projects done. I can spend more time solving real problems and less time dealing with infrastructure software. I will still look to server-side Java for projects that must scale and that require large development teams—the Java features that slow down development (static typing, verbose but readable code) also make Java better for very large development teams. That said, most projects are small enough to be quickly written by a few developers, and Ruby and Rails are a great fit for small and medium-sized projects (Sidebar 2. What If I Need to Scale? offers some suggestions for adding additional servers to handle increased user loads).

Deploying Rails applications to servers, however, has a reputation for being tricky—and if you are not familiar with Linux system administration it probably is. I hope that this article saves you time and aggravation in your deployments.



Mark Watson is a Java consultant and the author of 14 books on Java, artificial intelligence, C++, and intelligent agents.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap