Nginx

Nginx + 執行 RoR 應用程序的乘客在預期 302 時返回 401

  • April 23, 2018

我在 Nginx 之上的乘客上執行了一個 RoR 應用程序。我將設計用於我的身份驗證方法,並有一個連結通過電子郵件發送給需要身份驗證才能查看的使用者。

如果使用者從 Outlook 中點擊連結,並且 IE 是預設瀏覽器,則 IE 使用以下標頭髮出 HTTP 請求:

GET http://www.company.com/custom_layouts/108 HTTP/1.1
Accept: */*
Accept-Language: en-us
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: www.company.com

返回:

HTTP/1.1 401 未經授權的內容類型:/;charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Status: 401 X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15 WWW-Authenticate: Basic realm=“Application” Cache-Control: no-記憶體 X-UA 兼容:IE=Edge,chrome=1 設置 Cookie:_vxwer_session=

$$ sessionstr $$; 路徑=/; HttpOnly X-Runtime:0.011918 伺服器:nginx/0.7.67 + Phusion Passenger 2.2.15 (mod_rails/mod_rack) 31 您需要先登錄或註冊,然後才能繼續。0

當在地址欄中輸入完全相同的 URL 時,它會執行以下操作:

GET http://www.company.com/custom_layouts/108 HTTP/1.1
Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: en-US
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: www.company.com

返回:

HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 302
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15
Location: http://www.company.com/users/sign_in
Cache-Control: no-cache
X-UA-Compatible: IE=Edge,chrome=1
Set-Cookie: _xswer_session=[session_info_here]; path=/; HttpOnly
X-Runtime: 0.010798
Server: nginx/0.7.67 + Phusion Passenger 2.2.15 (mod_rails/mod_rack)

6f
<html><body>You are being <a href="http://www.company.com/users/sign_in">redirected</a>.</body></html>
0

我希望他們無論如何都會返回相同的東西。

在設計中查看以下與navigational_formats相關的原始碼。

我遇到了與您描述和設置相同的問題

config.navigational_formats = [:"*/*", :html]

在設計初始化程序中為我修復了它。我還不知道為什麼來自 Outlook 的 IE 請求會作為*/*傳遞。

引用自:https://serverfault.com/questions/222658