在服务器上部署rails app。 Unicorn和nginx日志似乎还可以。但我得到301错误

时间:2015-10-22 21:11:22

标签: ruby-on-rails nginx deployment unicorn

大家 我刚刚在服务器上部署了我的rails应用程序。我正在使用nginx,capistrano和独角兽。一切似乎都很好。但我有301错误,去服务器IP。 nginx.conf

   user nginx web;

   pid /var/www/run/nginx.pid;
   error_log /var/www/log/nginx.error.log;

   events {
   worker_connections 1024; # increase if you have lots of clients
   accept_mutex off; # "on" if nginx worker_processes > 1
   use epoll; # enable for Linux 2.6+

    }

http {
include mime.types;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
default_type application/octet-stream;
access_log /var/www/log/nginx.access.log combined;

sendfile on;

tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
tcp_nodelay off; # on may be better for some Comet/long-poll stuff


gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 0;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 9;
gzip_types text/plain text/xml text/css
         text/comma-separated-values
         text/javascript application/x-javascript
         application/atom+xml;

upstream app_server {
server unix:/var/sockets/.unicorn.app.sock fail_timeout=0;
}

server {
charset utf-8;

listen 80 default deferred; # for Linux
client_max_body_size 4G;
server_name _;


keepalive_timeout 5;

root /var/www/app/current/public;


try_files $uri/index.html $uri.html $uri @app;

location ~ ^/(assets)/  {
  root /var/www/app/current/public;

  expires max;
  add_header Cache-Control public;
}
location @app {

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


  proxy_set_header Host $http_host;


  proxy_redirect off;


  proxy_pass http://app_server;
}

# Rails error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
  root /var/www/app/current/public;
}

}

unicorn.rb

  worker_processes 2
  working_directory "/var/www/app/current"

  listen "/var/sockets/.unicorn.app.sock", :backlog => 64
  listen 8080, :tcp_nopush => true
  timeout 30
  pid "/var/www/app/current/tmp/pids/unicorn.pid"
  stderr_path "/var/www/app/current/log/unicorn.stderr.log"
  stdout_path "/var/www/app/current/log/unicorn.stdout.log"
  preload_app true
  GC.respond_to?(:copy_on_write_friendly=) and
  GC.copy_on_write_friendly = true
  check_client_connection false

  before_fork do |server, worker|

  defined?(ActiveRecord::Base) and
  ActiveRecord::Base.connection.disconnect!
  old_pid = "#{server.config[:pid]}.oldbin"
  if old_pid != server.pid
   begin
    sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
    Process.kill(sig, File.read(old_pid).to_i)
   rescue Errno::ENOENT, Errno::ESRCH
   end
  end
 end

  after_fork do |server, worker|
    defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
  end

我不知道我能告诉你的其他文件,所以要求它。 更新:以防万一,我正在使用狂欢。总而言之,当我输入服务器时,https打开,而不是http。

1 个答案:

答案 0 :(得分:0)

我解决了。我在位置@app {}块(nginx.conf)中注释了tproxy_set_header X-Forwarded-Proto $scheme;,这似乎解决了我的问题! 从这里开始https://github.com/spree/spree/issues/1728#issuecomment-6658147