我有一个配置为与Unicorn上游(它的rails应用程序)对话的nginx设置。我已经检查了基础知识。我知道请求是转到nginx,它映射到server_name,它找到try_files指令,它会转到最后一个指向@unicorn映射到位置块的指令。在位置块我有这个:
location @unicorn {
# an HTTP header important enough to have its own Wikipedia entry:
# http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# this helps Rack set the proper URL scheme for doing HTTPS redirects:
proxy_set_header X-Forwarded-Proto $scheme;
# pass the Host: header from the client right along so redirects
# can be set properly within the Rack application
proxy_set_header Host $http_host;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
proxy_pass http://unicorn_myapp;
}
然后进一步提升我的文件
upstream unicorn_myapp {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/etc/sockets/unicorn.myapp.sock;
}
我也有独角兽在同一个插座上听。这是我的独角兽conf文件中的一个片段:
# Use at least one worker per core if you're on a dedicated server,
# more will usually help for _short_ waits on databases/caches.
worker_processes 2
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/home/deployer/apps/myapp/current"
# listen on both a Unix domain socket
# we use a shorter backlog for quicker failover when busy
listen "/etc/sockets/unicorn.myapp.sock", :backlog => 64
我已验证两个守护进程正在运行,套接字文件是否存在(例如,独角兽正在侦听)并且没有权限问题,因为它会被记录。说到日志,每当我请求根目录时,nginx都会返回:
HTTP/1.1 301 Moved Permanently
Server: nginx/1.4.6
Date: Sun, 30 Mar 2014 21:05:55 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Status: 301 Moved Permanently
Location: https://myapp.com
这会记录在nginx的访问日志中:
xx.xx.xx.xx - - [30/Mar/2014:17:05:55 -0400] "GET / HTTP/1.1" 301 5 "-" "-"
Unicorn的日志中没有没有。可能会发生什么?
答案 0 :(得分:4)
我明白了。我实际上在我的production.rb文件中有force_ssl = true