The native nginx server does not meet the conditions for rails deployment, so nginx rewritten by passenger needs to be used.
sudo nano /opt/nginx/conf/nginx.confps:
- The model for rails to accept requests is that one process handles one request, and the efficiency of a single process is relatively low , generally need to open multiple processes
- passenger is a Rails application service management tool, which can uniformly manage the number of rails processes, life cycle, request queue, etc.
- nginx is a high-performance web server, because nginx handles links and static resources The ability is very strong, so nginx is usually placed before rails to accept client requests. The relationship is as shown below. Install passenger. Since nginx does not support dynamic module loading, passenger must be used. Compile and install nginx modified by passenger
<code> #安装passenger gem install passenger #接下来安装nginx passenger-install-nginx-module #ps:记得在安装过程中选择1,即完整安装 </code>Copy after login- 3. After the installation is completed, the system will prompt that the directory where nginx is installed, under centos7, is installed under /opt/nginx by default, and the configuration file is under /opt/nginx/conf/ by default. nginx.conf
4. Configure nginx (the most important part)
<code> { worker_processes 1; events { worker_connections 1024; } http { #这里是由passenger自己设置的 passenger_root /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.10; passenger_ruby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { #监听的端口 listen 80; server_name 127.0.0.1; #web根目录,一定是rails项目下的public root /var/www/furui_hisms/ironmine/public/; #一定要记得将这个选项设置为on passenger_enabled on; } } </code>
4. Start nginx to access (refer to my blog shell command under linux , taking starting and stopping nginx as an example)
5. Several nginx commands<code> #启动 sudo nginx #停止 sudo nginx -s stop #重启 sudo nginx -s reload </code>