


Rails environment construction and deployment (Nginx+Passenger) passenger side passenger seat a passenge
<span>Rails环境搭建与部署(Nginx+Passenger)</span> 1. 安装 Ruby 安装一些必要的依赖库: $ sudo apt-get install build-essential libssl-dev libyaml-dev libreadline-dev openssl curl git-core zlib1g-dev bison libxml2-dev libxslt1-dev libcurl4-openssl-dev nodejs 安装Ruby包管理器RVM $ curl -sSL https://rvm.io/mpapis.asc | gpg --import - $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 $ \curl -sSL https://get.rvm.io | bash -s stable $ rvm -v 如果看到rvm的版本号,就说明已经安装好了ruby。 使用RVM安装Ruby $ rvm install ruby-2.0.0-p643 $ ruby -v $ gem -v 察看ruby的版本和gem的版本,如果正确输出ruby的版本,即安装成功。
2.gem更换淘宝源(由于天朝墙太高,rubygems.org太慢,故使用ruby.taobao.org) $ gem sources -l
查看当前gem源
$ gem sources --remove https://rubygems.org/
删除当前gem源
$ gem sources -a https://ruby.taobao. org
增加国内源
<p> $ gem sources -u</p><p> 更新缓存</p>
2. 安装 Rails、Passenger 和 Nginx $ gem install rails bundler passenger Passenger 是一个比较好的 Rails 服务器,我们选择用它来运行 rails 并使用 Nginx 做反向代理。 们选择使用 apt 来安装 Passenger,先安装 PGP key $ rvmsudo passenger-install-nginx-module
所有都选默认,包括nginx安装目录业选择默认 /opt/nginx/ 3. 修改Nginx配置 $ sudo gedit /opt/nginx/conf/nginx.conf 加入如下代码: /*********************************/opt/nginx/conf/nginx.conf*********************************************/ user dawn; #设置用户名,非root用户 worker_processes 2; pid logs/nginx.pid; events { worker_connections 1024; } http { passenger_root /home/dawn/.rvm/gems/ruby-2.0.0-p643/gems/passenger-5.0.26; #passenger的安装目录 passenger_ruby /home/dawn/.rvm/gems/ruby-2.0.0-p643/wrappers/ruby; #ruby的安装目录 include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; #http配置 # server { # listen 80; # server_name 127.0.0.1; # charset utf-8; # #charset koi8-r; # # access_log logs/host.access.log; # # location / { # root /home/dawn/workspace/sample_app/public; # index index.html index.htm; # passenger_enabled on; # autoindex on; # # rails_env development; # rails_env production; # } # # #error_page 404 /404.html; # # # redirect server error pages to the static page /50x.html # # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # root html; # } # # # } # HTTPS server # server { listen 80; #保证直接访问网址可以进入https listen 443 ssl; server_name 127.0.0.1; charset utf-8; access_log logs/host.access.log; ssl_certificate /opt/nginx/conf/server.pem; #ssl证书的路径 ssl_certificate_key /opt/nginx/conf/server.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; location / { root /home/dawn/workspace/sample_app/public; index index.html index.htm; passenger_enabled on; autoindex on; autoindex_exact_size on; autoindex_localtime on; rails_env production; #rails环境设置为production,即生产模式 } #开启目录浏览功能,Rails开启目录浏览必须重新开启一个location location /download { root /home/dawn/workspace/sample_app/public; autoindex on; autoindex_exact_size on; autoindex_localtime on; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } /*************************************************分割线*******************************************************************/ 注1:生成ssl证书: x509证书一般会用到三类文,key,csr,crt。 Key 是私用密钥openssl格,通常是rsa算法。 Csr 是证书请求文件,用于申请证书。在制作csr文件的时,必须使用自己的私钥来签署申,还可以设定一个密钥。 crt是CA认证后的证书文,(windows下面的,其实是crt),签署人用自己的key给你签署的凭证。 1.key的生成 $ openssl genrsa -des3 -out server.key 2048 这样是生成rsa私钥,des3算法,openssl格式,2048位强度。server.key是密钥文件名。为了生成这样的密钥,需要一个至少四位的密码。可以通过以下方法生成没有密码的key: $ openssl rsa -in server.key -out server.key server.key就是没有密码的版本了。 2. 生成CA的crt $ openssl req -new -x509 -key server.key -out ca.crt -days 3650 生成的ca.crt文件是用来签署下面的server.csr文件。 3. csr的生成方法 $ openssl req -new -key server.key -out server.csr 需要依次输入国家,地区,组织,email。最重要的是有一个common name,可以写你的名字或者域名。如果为了https申请,这个必须和域名吻合,否则会引发浏览器 警报。生成的csr文件交给CA签名后形成服务端自己的证书。 4. crt生成方法 CSR文件必须有CA的签名才可形成证书,可将此文件发送到verisign等地方由它验证,要交一大笔钱,何不自己做CA呢。 $ openssl x509 -req -days 3650 -in server.csr -CA ca.crt -CAkey server.key -CAcreateserial -out server.crt 输入key的密钥后,完成证书生成。-CA选项指明用于被签名的csr证书,-CAkey选项指明用于签名的密钥,-CAserial指明序列号文件,而-CAcreateserial指明文件不存在时自动生成。 最后生成了私用密钥:server.key和自己认证的SSL证书:server.crt 证书合并: $ cat server.key server.crt > server.pem /*****************************************************分割线*****************************************************/ 这下打开浏览器访问localhost,即可看到nginx的欢迎界面。如果在root的目录添加了rails应用目录,即可看到网站的主页。
The above introduces the construction and deployment of Rails environment (Nginx+Passenger), including content on passenger and rails. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
