Nginx + Passenger部署rails

Nginx + Passenger

Nginx則是另外一套在Rails世界上還蠻常被使用的第二選擇,相較於Apache雖然功能較少,但運做效率更為良好。要讓Nginx裝上Passgener不须要先裝Nginx,只须要執行如下指令: mysql

$ sudo gem install passenger
$ sudo passenger-install-nginx-module

依赖PCRE nginx

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
三部曲:
./configure

make

sudo make install


报错: sql

error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or shell

ubuntu@ip-172-31-25-125:/usr/local/lib$ ln -s libpcre.so.1 /lib/libpcre.so.1

通常咱们在Linux下执行某些外部程序的时候可能会提示找不到共享库的错误, 好比: ubuntu


tmux: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory 缓存


缘由通常有两个, 一个是操做系统里确实没有包含该共享库(lib*.so.*文件)或者共享库版本不对, 遇到这种状况那就去网上下载并安装上便可.

另一个缘由就是已经安装了该共享库, 但 执行须要调用该共享库的程序的时候, 程序按照默认共享库路径找不到该共享库文件.

因此安装共享库后要注意共享库路径设置问题, 以下:

1) 若是共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令

ldconfig命令的用途, 主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下, 搜索出可共享的动态连接库(格式如lib*.so*), 进而建立出动态装入程序(ld.so)所需的链接和缓存文件. 缓存文件默认为/etc/ld.so.cache, 此文件保存已排好序的动态连接库名字列表.

2) 若是共享库文件安装到了/usr/local/lib(不少开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下, 那么在执行ldconfig命令前, 还要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中, 以下:

# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig

3) 若是共享库文件安装到了其它"非/lib或/usr/lib" 目录下,  可是又不想在/etc/ld.so.conf中加路径(或者是没有权限加路径). 那能够export一个全局变量LD_LIBRARY_PATH, 而后运行程序的时候就会去这个目录中找共享库.

LD_LIBRARY_PATH的意思是告诉loader在哪些目录中能够找到共享库. 能够设置多个搜索目录, 这些目录之间用冒号分隔开. 好比安装了一个mysql到/usr/local/mysql目录下, 其中有一大堆库文件在/usr/local/mysql/lib下面, 则能够在.bashrc或.bash_profile或shell里加入如下语句便可:

export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH   


通常来说这只是一种临时的解决方案, 在没有权限或临时须要的时候使用.

4)若是程序须要的库文件比系统目前存在的村文件版本低,能够作一个连接
好比:
error while loading shared libraries: libncurses.so.4: cannot open shared
object file: No such file or directory

ls /usr/lib/libncu*
/usr/lib/libncurses.a   /usr/lib/libncurses.so.5
/usr/lib/libncurses.so  /usr/lib/libncurses.so.5.3

可见虽然没有libncurses.so.4,但有libncurses.so.5,是能够向下兼容的
建一个连接就行了
ln -s  /usr/lib/libncurses.so.5.3  /usr/lib/libncurses.so.4


這是因為Passenger必須與Nginx一块儿編譯的關係,因此Passenger的安裝指令就包括了安裝Nginx。安裝完成之後,編輯/opt/nginx/conf/nginx.conf這個設定,將server那段改寫成以下: ruby

http {
    passenger_root /home/ubuntu/.rvm/gems/ruby-2.1.1/gems/passenger-4.0.49;
    passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.1.1/wrappers/ruby;

server {
    listen       80;
    server_name  www.yourhost.com;
    root /somewhere/public;
    passenger_enabled on;
}
相关文章
相关标签/搜索