gpt4 book ai didi

ruby-on-rails - 为什么 Nginx 一直返回 301?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:38:09 26 4
gpt4 key购买 nike

我有一个 nginx 设置,配置为与上游的 Unicorn 通信(它是一个 Rails 应用程序)。我已经检查了基础知识。我知道请求正在到达 nginx,它映射到 server_name,它找到 try_files 指令,它转到最后一个指令,即 @unicorn 映射到一个位置 block 。在位置 block 中我有这个:

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;
}

我也有 unicorn 在同一个 socket 上监听。这是我的 unicorn 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

我已经验证了两个守护进程都在运行,套接字文件存在(例如 unicorn 正在监听)并且没有权限问题,因为这会被记录下来。说到日志,每当我请求根目录时,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 的日志中没有。这里会发生什么?

最佳答案

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

关于ruby-on-rails - 为什么 Nginx 一直返回 301?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22749982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com