【发布时间】:2015-10-22 21:11:21
【问题描述】:
每个人 我刚刚在服务器上部署了我的 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;
}
}
独角兽.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。
【问题讨论】:
-
尝试在您的 nginx 配置中注释掉
error_page。 301 是一个相当奇怪的状态,要返回一个错误,删除它可能会显示 502。 -
刚试过。而且还是一样。 301.跨度>
-
您的应用程序或环境配置中是否有
config.force_ssl? -
是的,我把它设置为 true,然后设置为 false,但它没有帮助。但是,我在位置 @app{} 块中注释掉了
tproxy_set_header X-Forwarded-Proto $scheme;,这似乎解决了我的问题!从这里拿来github.com/spree/spree/issues/1728#issuecomment-6658147无论如何谢谢你)
标签: ruby-on-rails nginx deployment unicorn