简体   繁体   中英

Deploy rails app on server. Unicorn and nginx logs as it seems are ok. But I get 301 error

everyone I've just deployed my rails app on server. I'm using nginx, capistrano and unicorn. Everything seems to be working fine. But I have 301 error, going to server 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

I don't know what else files I can show you, so ask for it. Upd: just in case, I'm using spree. And well always, when I'm typing the server, https opens, not http.

I solved it. I commented out tproxy_set_header X-Forwarded-Proto $scheme; in the location @app{} block (nginx.conf) and that seemed to solved my problem! Took it from here https://github.com/spree/spree/issues/1728#issuecomment-6658147

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM