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 "-" "-"
有什麼在獨角獸的日誌。這裏會發生什麼?
應用程序根目錄config/unicorn.rb中應該有一個文件,其中有一行「listen APP_PATH +」/tmp/pids/.unicorn。襪子「,:backlog => 64',它描述了Unicorn插槽的位置,供nginx服務器收聽。這是否符合你的nginx配置? –
它確實符合耶。如果你仔細觀察,我實際上是在原始文章中發佈了這個文件。 – asolberg
除非用戶「部署者」在/ etc/sockets目錄(我嚴重懷疑)具有寫權限,否則這是絕對正常的。您可以通過進入/ etc/sockets並執行下列其中一項操作來檢查:如果您說unicorn.log爲空,只需執行「touch unicorn.log」即可。您可能會看到一個錯誤。如果不是,那麼「mv unicorn.log unicorn.log.bak && unicorn.log」。你可能會看到一個錯誤。我建議你改變你的套接字的位置到你的rails文件夾中的臨時文件夾中,正如我在之前的評論中展示的那樣。如果沒有,至少將該文件寫入「deployer」 –