A simple guide on how to install nginx from source with passenger and ruby enterprise edition.
Hopefully you've been hearing some
comments over the last while about how good the package management
story is with Linux and Ruby. Basically, Ubuntu/Debian makes use of
Aptitude, while Ruby makes use of RubyGems. Aptitude in particular has
made installing things on Linux quicker and easier than Windows.
In most cases the package you get from aptitude is exactly what you
want. However, you'll sometimes want a build with a non default
configuration. In such cases you'll have to grab the source, configure
your makefile, build and install. I admit that it can be a little
intimidating at first, but it really is easy, and it'll cover that last
5% that Aptitude can't. (there's actually a much easier way to get
passenger/nginx up and running, but its good to know and understand the
linux build process)
What we are going to look at in specific is configuring nginx
to use Phusion Passenger
- the combination is quickly becoming the preferred way to host Ruby on
Rails. Even if you aren't interested in Rails development, nginx is
very popular and super-fast reverse proxy/load balancer/http server
used in front of many IIS boxes, so its good to be familiar with it.
Depending on what's already on your box, some of these steps might
be unnecessary. Also, I'm not an expert at this - if it doesn't work,
try and figure it out (it didn't work at first for me either, but
google is great
Step 1 - Get The Source
The first step is to download the nginx source. You can do this however you like, but wget http://sysoev.ru/nginx/nginx-0.8.43.tar.gz
is probably the quickest way (you should check the nginx download page
to see if there's a newer version than 0.8.43).
Step 2 - Untar It
Next we have to unarchive and decompress the source using the tar
command: tar -xvf nginx-0.8.43.tar.gz
. This creates a folder named nginx-0.8.43
.
Step 3 - Setup
You'll probably need to install the core build tools, which you can do by executing apt-get install build-essential
. You'll also want to install Ruby. I use REE (Ruby Enterprise Edition). Download the latest source (using wget) from here
,
untar it, and run the installer. It'll walk you through the
installation processing - telling which and how to install missing
dependencies. Once done, we can add ruby's bin folder to our path: export PATH=$PATH:/opt/ruby-enterprise-1.8.7-2010.02/bin/
(your path may be different)
Next we install the passenger phusion gem: gem install passenger
.
Step 4 - Configure
In following steps we'll make (which builds the code) and then make
install (which installs the built code). Before we do that we need to
generate a MakeFile (which those two steps use). This is where we
change our package from what we could otherwise get from Aptitude
(that's essentially what Aptitude does, it gives us a pre-configured
and pre-built package). The nginx install page
gives us the possible compile-time options as well as samples. We can
run one of the samples from the nginx page (all it does is create a
Makefile, so go ahead and play with it). Change to the nginx directory
and run (./XYZ is how you execute XYZ in Linux, the \ lets us break the
command across multiple lines):
02
|
--conf-path=/etc/nginx/nginx.conf \
|
03
|
--error-log-path=/var/log/nginx/error.log \
|
04
|
--pid-path=/var/run/nginx.pid \
|
05
|
--lock-path=/var/lock/nginx.lock \
|
06
|
--http-log-path=/var/log/nginx/access.log \
|
07
|
--with-http_dav_module \
|
08
|
--http-client-body-temp-path=/var/lib/nginx/body \
|
09
|
--http-proxy-temp-path=/var/lib/nginx/proxy \
|
10
|
--with-http_stub_status_module \
|
11
|
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
|
13
|
--with-http_flv_module
|
You'll probably get some errors - for example, I'm told that the
HTTP rewrite module requires the PCRE library. I'm also given some
options. We can install PCRE, tell nginx to skip loading the HTTP
rewrite module, or point nginx to the PCRE source. You can install PCRE
by running apt-get install libpcre3 libpcre3-dev
. You'll
probably get more errors which you can resolve however you want (by
installing the necessary library (it isn't always easy to know what
library you need), or skipping the module).
Step 5 - More Headers Module
The above is just a sample, we're going to build nginx exactly how
we want it. First though, I need to download any extra module I want to
build with. I'm particularly interested in More Headers Module
,
which gives us more control over headers than what can be done with the
core. Its pretty easy, download the latest version form github page
, untar it, and we can now configure nginx to use this module via the add-module directive: --add-module=/root/headers-more-nginx-module
.
Step 6 - Our Configure
Here's the actual configuration options I'll be using:
02
|
--conf-path=/etc/nginx/nginx.conf \
|
03
|
--error-log-path=/var/log/nginx/error.log \
|
04
|
--pid-path=/var/run/nginx.pid \
|
05
|
--lock-path=/var/lock/nginx.lock \
|
06
|
--http-log-path=/var/log/nginx/access.log \
|
07
|
--http-client-body-temp-path=/var/lib/nginx/body \
|
08
|
--http-proxy-temp-path=/var/lib/nginx/proxy \
|
09
|
--without-http_fastcgi_module \
|
10
|
--without-http_uwsgi_module \
|
11
|
--with-http_stub_status_module \
|
12
|
--with-http_gzip_static_module \
|
13
|
--add-module=/root/headers-more-nginx-module \
|
14
|
--add-module=/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/nginx
|
As you can see I've disabled a couple built-in modules, added a
couple ones, and added our more-header and passenger module. The path
of your passenger module might be different, but it should be similar
except for the possibility of different version numbers.
Step 7 - Make
Now that we have everything configured, we can build it. To do so, simply run make
. Once completed, you can install it by running make install
.
Step 8 - Configuring nginx
You'll want to configure nginx to fit your specific needs, but to
get passenger working you'll need to specify these two directives (in
the http section of the configuration):
1
|
passenger_root /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15;
|
2
|
passenger_ruby /opt/ruby-enterprise-1.8.7-2010.02/bin/ruby;
|
also, you specify passenger_enabled on
within the appropriate nginx locations
Step 9 - Final touches
You'll want a start/stop script for nginx, you can grab mine
, place it in /etc/init.d
, give it execute permission chmod +x /etc/init.d/nginx
and use /etc/init.d/nginx start|stop|restart|reload
(if it fails because of missing directories, go ahead and create them
and try again). Finally, we can make nginx auto start by executing /usr/sbin/update-rc.d -f nginx defaults
.
Conclusion
Hopefully you have everything up and running. All you need to do is
read up on nginx configuration to set up your sites. A long time ago I
remember configuring/making and not really getting it. Now it all seems
pretty trivial. Hopefully you think so too, and remember, if you screw
anything up or want to change something (like include another module),
you can just start the process over (remember to stop relevant running
processes (like nginx) and to make/make install after configuring.)
相关推荐
Installing Oracle 10G On Linux
Installing Oracle Database 11g on Linux
installing oracle9i on redhat linux.rar 分布讲述在redhat上安装oracle9i的全过程和注意事项!
Installing STLinux on Ubuntu
2 Installing Qt SDK on X86 Linux 3 Installing Qt Everywhere on a Linux host 3.1 Install and build tslib 3.2 Install Qt Everywhere on a Linux Host 3.3 Install Qt Everywhere 4.6.3 fonts and ...
Step By Step guide for installing Oracle RAC 11gR2 on Linux
oracle完整安装文档,for linux
Installing Oracle RAC 10g Release 2 on Linux x86(中)
NULL 博文链接:https://wsfei.iteye.com/blog/1830846
Now it's time to compile and install Asterisk. Let's change to the directory which contains the Asterisk source code. 从源代码安装 asterisk sipserver VOIP RTP pjsip webrtc
Installing Android development kits on Linux Time for action – installing Android SDK and NDK on Ubuntu Setting up the Eclipse development environment Time for action – installing Eclipse ...
2.2. Installing MySQL from Generic Binaries on Unix/Linux 2.3. Installing MySQL on Microsoft Windows 2.3.1. MySQL Installation Layout on Microsoft Windows 2.3.2. Choosing An Installation Package 2.3.3...
■Chapter 2: Installing Nginx .................................................................................. 17 ■Chapter 3: Nginx Core Directives ....................................................
Installing Activ Test on Your PC
Installing Kali Linux Understanding File Systems and Storage Media Incident Response and Data Acquisition Evidence Acquisition and Preservation with DC3DD and Guymager File Recovery and Data Carving ...
This article describes the installation of Oracle Database 11g release 2 (11.2.0.3 64-bit) RAC on Linux (Oracle Linux 6.3 64-bit) using VirtualBox (4.2.6) with no additional shared disk devices. ...
Installing RAC on AIX
Installing SQL Server 2008 on a Windows Server 2008 Cluster