Detailed records of deploying rails 4 in nginx + puma

Source: Internet
Author: User

It took two weeks for Google to deploy the method. Many methods were useless. I finally used the control variable method to modify the configuration file one by one.

First,/etc/nginx/vhosts/limlog.sloger.info. conf and config/puma. rb

## /etc/nginx/vhosts/limlog.sloger.info.conf# upstream limlog {  server   unix:///tmp/limlog.sock;} server {  listen 80;  server_name     limlog.sloger.info;   root        /srv/http/limlog.sloger.info/public;   access_log     /var/log/nginx/limlog-access.log;  error_log      /var/log/nginx/limlog-error.log info;   location / {    expires      max;    add_header     Cache-Control public;     proxy_redirect   off;    proxy_set_header  Host        $http_host;    proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;     proxy_pass     http://limlog;  }   location ~ ^/assets/ {    expires   1y;    gzip_static on;    add_header ETag "";    add_header Cache-Control public;    break;  }}
#!/usr/bin/env ruby -w ## config/puma.rb# rails_env = ENV['RAILS_ENV'] || 'development' threads 4, 4 bind 'unix:///tmp/limlog.sock'pidfile '/tmp/limlog.pid'state_path '/tmp/limlog.state' activate_control_app

Modify the root server_name upstream in the nginx configuration file to yours. Where is each file, and write it in the file header comment.

Then, modify config/environmens/production. rb.

Change "false" to "true" for 18 rows

# Disable Rails's static asset server (Apache or nginx will already do this).config.serve_static_assets = true

29 lines uncomment

# Specifies the header that your server uses for sending files.# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apacheconfig.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

Then the app/controller/application_controller

Line 2 parameter with: exception removed

protect_from_forgery

However, this is secret_key_base.

My approach is to create a file env. sh

# Use rake secret to generate the key, and paste it in the following format: =: export SECRET_KEY_BASE = # various environment variables can be export

Start

Start or restart nginx

Import the environment variable source env. sh

Start rails bundle exec-C config/puma. rb-e production

Now the deployment is complete, and the most troublesome assets are also solved ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.