MacOS下Rails+Nginx+SSL环境的搭建(上)

来源:互联网 发布:ip地址和端口的关系 编辑:程序博客网 时间:2024/06/03 20:55

这里把主要的步骤写下来,反正我是走了不少弯路,希望由此需求的朋友们别再走类似的弯路.虽说环境是在MacOS下搭建,但是基本上和linux下的很相像,大家可以举一反三.

一.安装Rails

这个是最简单的,大家可以到我blog看相关文章,安装完毕后创建一个rails项目,比如名字为rails_project,这时你启动rails服务器之后rails s,应该可以在浏览器中访问如下地址的页面:

http://localhost:3000

至此,Rails安装和后台服务都运行正常!

二.安装Passenger和Nginx

首先是gem中安装passenger包:

gem install passenger

敲入如下指令安装Nginx:

passenger-install-nginx-module1.Yes: download, compile and install Nginx for me. (recommended) The easiest way to get started. A stock Nginx 1.0.10 with Passenger support, but with no other additional third party modules, will be installed for you to a directory of your choice.2.No: I want to customize my Nginx installation. (for advanced users) Choose this if you want to compile Nginx with more third party modules besides Passenger, or if you need to pass additional options to Nginx's 'configure' script. This installer will 1) ask you for the location of the Nginx source code, 2) run the 'configure' script according to your instructions, and 3) run 'make install'.

在遇到以上选择的时候选择1,当询问Nginx安装路径的时候,建议安装到/usr/local/nginx下.

安装完毕后会在nginx的配置文件中(/usr/local/nginx/conf/nginx.conf)自动加入以下两行:

http { ... passenger_root /Users/Daniel/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.10; passenger_ruby /Users/Daniel/.rvm/wrappers/ruby-1.9.2-p290/ruby; ... }server { listen 80; server_name www.yourhost.com; root /somewhere/public; # <--- be sure to point to 'public'! passenger_enabled on; }

这时你可以测试一下安装是否成功:

rvmsudo passenger-config validate-install * Checking whether this Phusion Passenger install is in PATH...* Checking whether there are no other Phusion Passenger installations...

如果你不是通过brew之类安装的nginx, 比如这里我们就不是,你要自己手动添加nginx到执行路径中去:

ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
0 0
原创粉丝点击