2014-03-30 68 views
1

我有一个配置为与Unicorn上游(其轨道应用程序)交谈的nginx设置。我已经检查了基本知识。我知道请求正在到达nginx,它与server_name的映射,它找到了try_files指令,它落在@unicorn映射到位置块的最后一个指令。在定位块我有这样的:为什么Nginx继续返回301?

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 "-" "-" 

什么在独角兽的日志。这里会发生什么?

+0

应用程序根目录config/unicorn.rb中应该有一个文件,其中有一行“listen APP_PATH +”/tmp/pids/.unicorn。袜子“,:backlog => 64',它描述了Unicorn插槽的位置,供nginx服务器收听。这是否符合你的nginx配置? –

+0

它确实符合耶。如果你仔细观察,我实际上是在原始文章中发布了这个文件。 – asolberg

+0

除非用户“部署者”在/ etc/sockets目录(我严重怀疑)具有写权限,否则这是绝对正常的。您可以通过进入/ etc/sockets并执行下列其中一项操作来检查:如果您说unicorn.log为空,只需执行“touch unicorn.log”即可。您可能会看到一个错误。如果不是,那么“mv unicorn.log unicorn.log.bak && unicorn.log”。你可能会看到一个错误。我建议你改变你的套接字的位置到你的rails文件夹中的临时文件夹中,正如我在之前的评论中展示的那样。如果没有,至少将该文件写入“deployer” –

回答

3

我明白了。我在我的production.rb文件中实际上有force_ssl = true

相关问题