Mac nginx with rails

我只是一个虾纸丫 提交于 2021-01-29 02:05:01

问题


I just installed nginx on my mac. Now I have no clue how to get RoR working with it. Before what I was doing was using Webrick and it was simple, i would just cd in my RoR dir and start the server. How can I do this with nginx?

Thanks


回答1:


I recently had to install and configure a local development stack consisting of Nginx, Passenger 4, and Ruby 2 on Mac OS X Lion. I documented the steps for my team in a blog post:

http://jrmyward.com/blog/posts/local-rails-development-with-nginx-passenger-4-and-ruby-2-on-mac-os-x




回答2:


I also develop locally on my mac on nginx. I used the following tutorial to get started: http://trevorturk.com/2010/09/22/passenger-with-nginx-on-mac-os-x-2nd-edition-2/

and of course the following railscasts helps a lot: http://railscasts.com/episodes/293-nginx-unicorn




回答3:


You can use passenger for working with ROR and Nginx Steps for installing Ruby with rvm:

1)$ rvm list known

2)$ rvm install ruby-2.1.0 //use any latest version

3)$ rvm use 2.1.0 --default

Install Passenger:

1)$ sudo gem install passenger

Install Nginx:

1)$ brew update (I am using homebrew installer)

2)$ brew install nginx --with-passenger

Configure Nginx:

1)Open /usr/local/etc/nginx/nginx.conf file in any editor 2)delete add server { } blocks and add following

server {
listen 3000;
server_name product.example.local;  
root /Users/username/code/product/public;
access_log /Users/username/code/product/log/nginx_access.log;
error_log /Users/username/code/product/log/nginx_error.log;
}

here

server_name will be '<'ror project name'>'.local

root will be '<'path to your ror project'>'/public

access_log will be '<'path to your ror project'>'/log/nginx_access.log

error_log will be '<'path to your ror project'>'log/nginx_error.log

In http{ block at first line add

http {
passenger_root /usr/local/opt/passenger;
passenger_ruby /Users/username/.rvm/wrappers/ruby-2.0.0-p247/ruby;

you can get passenger_root and passenger_ruby after you install nginx

$ brew install nginx --with-passenger on command prompt

like

To activate Phusion Passenger, add this to /usr/local/etc/nginx/nginx.conf, inside the 'http' context:
passenger_root /usr/local/opt/passenger/libexec/lib/phusion_passenger/locations.ini; passenger_ruby /usr/bin/ruby;

ok! you are done with installation just start nginx now

$ sudo nginx

after that open browser and call

http://localhost:3000

you can stop nginx with

$ sudo nginx -s stop



来源:https://stackoverflow.com/questions/8648587/mac-nginx-with-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!