0、假设你RoR环境装好了
1、安装Passenger
1 gem installed
2、安装Nginx
⬢ Python
⬢ Node.js
⬢ Meteor
* To install C++ compiler:
Please install it with apt-get install build-essential
* To install Curl development headers with SSL support:
Please run apt-get install libcurl4-openssl-dev or libcurl4-gnutls-dev, whichever you prefer.
* To install OpenSSL development headers:
Please install it with apt-get install libssl-dev
If the aforementioned instructions didn't solve your problem, then please take
a look at our documentation for troubleshooting tips:
https://www.phusionpassenger.com/library/install/nginx/
https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/
$ sudo apt-get install build-essential libcurl4-openssl-dev libssl-dev
$ passenger-install-nginx-module
1. Yes: download, compile and install Nginx for me. (recommended)
The easiest way to get started. A stock Nginx 1.12.1 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,1代表自动完整安装并配置nginx,2是代表根据自己需求定制nginx
Please specify a prefix directory [/opt/nginx]:
这个步骤是选择Nginx的安装目录,可以直接选择默认/opt/nginx。记住此处的安装目录。
This installer has already modified the configuration file for you! The
following configuration snippet was inserted:
http {
...
passenger_root /var/lib/gems/2.2.0/gems/passenger-5.1.6;
passenger_ruby /usr/bin/ruby2.2;
...
}
After you start Nginx, you are ready to deploy any number of Ruby on Rails
applications on Nginx.
3、Nginx项目配置
passenger_root /var/lib/gems/2.2.0/gems/passenger-5.1.6;
passenger_ruby /usr/bin/ruby2.2;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 3333;
server_name 127.0.0.1;
root /home/thinking/Documents/test_app/public;
passenger_enabled on;
rails_env production;
}
4、为项目配置安全密钥
gem 'dotenv-rails'
然后运行
bundle install
然后运行
rake secret
SECRET_KEY_BASE = 你的密钥
最后修改项目根目录下的config/secrets.yml
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
test:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
rails db:migrate RAILS_ENV=production
5、运行和停止
root 42926 1976 0 23:40 ? 00:00:00 nginx: master process /opt/nginx/sbin/nginx
$ sudo kill -QUIT 42926
OR
$ sudo /opt/nginx/sbin/nginx -s quit
6、出现Permission denied (errno=13)错误
解决:
参照提示https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/?a=upon-accessing-the-web-app-nginx-reports-a-permission-denied-error
执行sudo chmod -R g+x,o+x your_ror_proj_path