rails + nginx + passenger环境搭建

来源:互联网 发布:java变量的主要类型 编辑:程序博客网 时间:2024/06/06 02:58
    最近一直在做rails开发,偶然间看到篇文章说rails的server服务器不成熟,开源的服务器一大堆,但是每个或多或少都有问题,后来在ruby china社区闲逛时了解到passenger是一款不错的rails服务器,然后就想动手搭建起来试试。搭建的过程还是比较顺利。因为公司办公环境有网络限制,所以用到的安装包都是下载后安装的(使用能上网的机器在线安装后,直接把cache目录拷贝过来安装,这样可以解决gem依赖问题)。具体过程如下:
         
         1.本地安装passenger. 进入到上面步骤中的cache目录, 执行命令:gem installpassenger-5.0.23.gem -l
         2. 安装PCRE库(pcre-8.34.tar.gz),使用默认安装;

   tar -zxvfpcre-8.34.tar.gz;

   cd pcre-8.34

   ./configure=/usr/local/pcre-8.34  #安装目录,可自定义

   make

   make install

3.下载nginx安装包并解压:nginx-1.8.0.tar.gz(注意:这里只需要下载和解压即可,不需要安装)

4. ruby的安装目录下执行:passenger-install-nginx-module(passenger在安装时会在ruby bin目录下增加一些文件)

开始安装后,按照需要的部署需求做对应的选择即可。

直到遇到以下选择:

1.Yes:download, compile and install Nginx for me. (recommended)

Theeasiest way to get started. A stock Nginx 1.0.10 with Passenger

support,but with no other additional third party modules, will be

installedfor you to a directory of your choice.

 

2.No:I want to customize my Nginx installation. (for advanced users)

Choosethis if you want to compile Nginx with more third party modules

besidesPassenger, or if you need to pass additional options to Nginx's

'configure'script. This installer will 1) ask you for the location of

theNginx source code, 2) run the 'configure' script according to your

instructions,and 3) run 'make install'.

Whicheveryou choose, if you already have an existing Nginx configuration file,

thenit will be preserved.

 

Enteryour choice (1 or 2) or press Ctrl-C to abort:

 

这里因为网络原因不能在线自动安装,所以我选择第二中方式,用户自定义安装。然后输入在第3步下载的nginx解压路径,然后会自动编译和安装。

 


 

安装完成后会到如上界面,拷贝红线标识的两行信息,复制到nginx.conf文件中。最终的nginx.conf配置内容如下:

{

  worker_processes  1;

 

  events {

      worker_connections  1024;

  }

 

  http {

      passenger_root /usr/local/ruby-2.1.7/lib/ruby/gems/2.1.0/gems/passenger-5.0.23;

      passenger_ruby /usr/local/ruby-2.1.7/bin/ruby;

 

      include       mime.types;

      default_type  application/octet-stream;

 

      sendfile        on;

      keepalive_timeout  65;

      server {

          #监听的端口

          listen       8080;

          server_name  127.0.0.1;

          #web根目录,一定是rails项目下的public

          root /var/www/sample_app/public/;

          #一定要记得将这个选项设置为on

          passenger_enabled on;

          #生产环境需要配置密钥文件,我们当前先配置成开发环境

          rails_env development;

 

      }   

  }


 接下来可以启动nginx了,执行:sudo/usr/local/nginx/sbin/nginx

 然后启动报错:

    

[root@SZB-L0016361conf]# /usr/local/nginx/sbin/nginx

/usr/local/nginx/sbin/nginx:error while loading shared libraries: libpcre.so.1: cannot open shared objectfile: No such file or directory

 

从错误看出是缺少lib文件导致,进一步查看下

[root@localhostconf]# ldd $(which /usr/local/nginx/sbin/nginx)

linux-gate.so.1=> (0x0071b000)

libpthread.so.0=> /lib/libpthread.so.0 (0×00498000)

libcrypt.so.1=> /lib/libcrypt.so.1 (0×00986000)

libpcre.so.1=>not found

libcrypto.so.6=> /lib/libcrypto.so.6 (0×00196000)

libz.so.1=> /lib/libz.so.1 (0×00610000)

libc.so.6=> /lib/libc.so.6 (0x002d7000)

/lib/ld-linux.so.2(0x006a8000)

libdl.so.2=> /lib/libdl.so.2 (0x008c3000)

 

可以看出 libpcre.so.1 => not found并没有找到,进入/lib目录中手动链接下

 

[root@SZB-L0016361lib]# ln -s libpcre.so.0.0.1 libpcre.so.1

 

执行后重启仍然报错,然后网上查找原因,发现是因为我的操作系统是64位,需要链接到lib64目录下:

ln-s /usr/local/lib/libpcre.so.1 /lib64/

 

然后重启,访问OK.

1 0
原创粉丝点击