Tag Archives: passenger

Drive Rails on Nginx and Passenger, Install Instructions


I setup rails on Passenger and Nginx. But I didn’t install from package, but compiled the source to hide some http response header. I wrote the instruction to install them, and what I did.

Environment

  • Ruby 2.2.2
  • Nginx 1.8
  • Passenger 5.0.18
  • EC2 Amazon Linux 2015.03

Overview

I suppose you installed ruby.

  1. Install Passenger
  2. Install Nginx
    • Download Nginx and required module
    • Compile and Install
  3. nginx configuration
  4. (Re)Boot nginx

Install Passenger

Install Passenger, as gem install passenger.

Install Nginx

If you execute passenger-install-nginx-module as root, nginx will be installed. But in the case, Nginx version and Passenger version should be presented in http response header.

For removing such no use headers, you should compile the source of nginx with nginx module.

Download Nginx and required module

Execute sudo su -, and switch user to root. And execute cd /usr/local/src.

Download Nginx

Download Nginx (tar.gz format). I downloaded Nginx 1.8.0, which was the latest stable nginx. You can find it at Nginx Official Download Page.

And extract it.

Download headers-more-nginx-module

Plain Nginx and Passenger respond http header including versions of Nginx and Passenger, and execution time, etc. Not to expose server’s internal information, use headers-more-nginx-module with Nginx.

I got the module (.tar.gz format) of latest version from github, which is on github.

Release list page : Releases · openresty/headers-more-nginx-module

After downloading, Extract it.

After extraction, change the .tar.gz file name to understandable name. Tab helps you to change the name, using extracted directory name.

Compile and Install

The installer require the following components. If there’s any deficit, installation will be stopped, so don’t worry.

  • C compiler (/usr/bin/cc)
  • C++ compiler (/usr/bin/c++)
  • wget or curl
  • curl development header with ssl support
  • Openssl development header
  • Zlib development header
  • rake, rack, ruby development header, rubygems

If you have installed nginx into the same place in the same way, the name old nginx binary will be changed to nginx.old.

Swap

If the RAM is less than 1 GB, like EC2 micro instance, swap memory is required. Execute the following commands as root.

Don’t worry, even if you start installation with small amount of memory, instruction is shown in installation process.

Execute passenger-install-nginx-module, with no option.

Now, the installation will start.

まずは 処理の説明が表示され、 Press Enter to continue, or Ctrl-C to abort. と表示されます。 Enter を押して続行します。 途中で()めたくなったら いつでも Ctrl-C を押せば止められます。

続いて Which languages are you interested in? と表示されるので 必要なものを画面の指示にしたがって選択し、 Enter を押します。

インストールされているソフトウェアのチェックが終わると、Do you want this installer to download, compile and install Nginx for you? と、 インストール方法を聞かれます。 ソースからコンパイルを行うので 2. No: I want to customize my Nginx installation. (for advanced users) を選びます。

And in my case, not installed component PCRE was automatically downloaded and installed.

Next, you should input source file location and compile option. I inputted the following.

Where is your Nginx source code located?
/usr/local/src/nginx-1.8.0
Where do you want to install Nginx to?
Pressed Enter, without any character.
Extra Nginx configure options
--add-module=/usr/local/src/headers-more-nginx-module-0.261
To use headers-more-nginx-module, add --add-module. Options set as default is printed on console.

At last, confirmation message will be shown, then Enter if there is no mistake. And compiling and installing will be started.

nginx configuration

I copied /opt/nginx/conf/nginx.conf.default to /opt/nginx/conf/nginx.conf.

For running Rails application, the following configuration helps. I show a part of the configuration. I set client_max_body_size 10 MB for uploading images. (It’s 1M as default.) Other configuration setting is explained on Phusion Passenger users guide, Nginx version or so.

And add code to modify response header.

Check the configuration file with the following command. It’s ok if no error is shown.

(Re)Boot Nginx

I usually use /opt/nginx/sbin/nginx -s reload for rails reloading, but it wasn’t effective in this case.

Stop Nginx with the command /opt/nginx/sbin/nginx -s stop, and boot it by execution of /opt/nginx/sbin/nginx.

If you launch nginx first time, only execute /opt/nginx/sbin/nginx.