有没有人有幸用SSL配置Passenger和Nginx?我花了好几个小时试图让这个配置按照我的意愿运行,使用网上的资源很少,而且我无法在Rails控制器中显示任何所谓的转发标头.
例如,使用以下conf文件(及其多种变体):
server {
listen 3000;
server_name .example.com;
root /Users/website/public;
passenger_enabled on;
rails_env development;
}
server {
listen 3443;
root /Users/website/public;
rails_env development;
passenger_enabled on;
ssl on;
#ssl_verify_client on;
ssl_certificate /Users/website/ssl/server.crt;
ssl_certificate_key /Users/website/ssl/server.key;
#ssl_client_certificate /Users/website/ssl/CA.crt;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X_FORWARDED_PROTO https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-SSL-Subject $ssl_client_s_dn;
#proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_redirect off;
proxy_max_temp_file_size 0;
}
和控制器中的Rails代码如下:
request.headers.each { |k,v|
RAILS_DEFAULT_LOGGER.error "Header #{k} Val #{v}"
}
Header rack.multithread Val false
Header REQUEST_URI Val /login/new
Header REMOTE_PORT Val 64021
Header rack.multiprocess Val true
Header PASSENGER_USE_GLOBAL_QUEUE Val false
Header PASSENGER_APP_TYPE Val rails
Header SCGI Val 1
Header SERVER_PORT Val 3443
Header HTTP_ACCEPT_CHARSET Val ISO-8859-1,utf-8;q=0.7,*;q=0.7
Header rack.request.query_hash Val
Header DOCUMENT_ROOT Val /Users/website/public
我甚至修改了Passenger的abstract_request_handler的main_loop方法,即
headers,input = parse_request(client)
if headers
if headers[REQUEST_METHOD] == PING
process_ping(headers,input,client)
else
headers.each { |h,v|
log.unknown "abstract_request_handler: #{h} = #{v}"
}
process_request(headers,client)
end
end
abstract_request_handler: HTTP_KEEP_ALIVE = 300
abstract_request_handler: HTTP_USER_AGENT = Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5
abstract_request_handler: PASSENGER_SPAWN_METHOD = smart-lv2
abstract_request_handler: CONTENT_LENGTH = 0
abstract_request_handler: HTTP_IF_NONE_MATCH = "b6e8b9afbc1110ee3bf0c87e119252ad"
abstract_request_handler: HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5
abstract_request_handler: SERVER_PROTOCOL = HTTP/1.1
abstract_request_handler: HTTPS = on
abstract_request_handler: REMOTE_ADDR = 127.0.0.1
abstract_request_handler: SERVER_SOFTWARE = Nginx/0.7.61
abstract_request_handler: SERVER_ADDR = 127.0.0.1
abstract_request_handler: SCRIPT_NAME =
abstract_request_handler: PASSENGER_ENVIRONMENT = development
abstract_request_handler: REMOTE_PORT = 64021
abstract_request_handler: REQUEST_URI = /login/new
abstract_request_handler: HTTP_ACCEPT_CHARSET = ISO-8859-1,*;q=0.7
abstract_request_handler: SERVER_PORT = 3443
abstract_request_handler: SCGI = 1
abstract_request_handler: PASSENGER_APP_TYPE = rails
abstract_request_handler: PASSENGER_USE_GLOBAL_QUEUE = false
我已经厌倦了把头撞在墙上,所以我真的很感激我能得到的任何帮助!
最佳答案
Passenger 3使用新指令passenger_set_cgi_param实现此功能,其行为类似于proxy_set_header.
例如,要将SSL变量传递给Rack,您可以这样做:
server {
listen 443 default ssl;
# other SSL stuff goes here
# other passenger stuff here
passenger_set_cgi_param X_FORWARDED_PROTO https;
passenger_set_cgi_param X-SSL-Raw-Cert $ssl_client_raw_cert;
passenger_set_cgi_param X-SSL-Cert $ssl_client_cert;
passenger_set_cgi_param X-SSL-Client-S-DN $ssl_client_s_dn;
passenger_set_cgi_param X-SSL-Client-I-DN $ssl_client_i_dn;
passenger_set_cgi_param X-SSL-Client-Verify $ssl_client_verify;
}
然后,您可以访问X-SSL-Raw-Cert和Rack :: Request实例中的其他标头(可从控制器中的#request访问).
它还没有记录,但这里有更多信息:
> http://code.google.com/p/phusion-passenger/issues/detail?id=464&q=nginx%20ssl&colspec=ID%20Type%20Status%20Priority%20Milestone%20Stars%20Summary#c1
> http://groups.google.com/group/phusion-passenger/browse_thread/thread/216040342e546e90/e9515591a4722fb3?lnk=raot