[英]How to configure SSL termination on Nginx with a Rails application
I get my SSL request through a load balancer which is performing SSL termination and sending the decrypted traffic to my server on port 81. 我通过负载均衡器获取SSL请求,负载均衡器执行SSL终止并将解密的流量发送到端口81上的服务器。
I'm running Nginx and have setup a listener to the port 81 and I would like to tell my Rails app that this is a SSL request. 我正在运行Nginx并设置了一个端口81的监听器,我想告诉我的Rails应用程序这是一个SSL请求。
Here is how my Nginx config looks like: 这是我的Nginx配置的样子:
server {
listen 81;
server_name SERVER;
root /var/www/app/current/public;
error_log /var/log/nginx/app-error.log;
access_log /var/log/nginx/app-access.log;
passenger_enabled on;
client_max_body_size 100M;
location / {
passenger_enabled on;
proxy_set_header X-FORWARDED-PROTO https;
}
}
It goes through but Ruby on Rails doesn't detect the header request.headers['X-Forwarded-Proto'], so it takes the request as non-https. 它通过但Ruby on Rails没有检测到头request.headers ['X-Forwarded-Proto'],所以它将请求作为非https。 What should I add in order to get Rails thinking this is a SSL request?
为了让Rails认为这是一个SSL请求,我应该添加什么?
因此乘客不使用proxy_set_header,您需要使用passenger_set_cgi_param:
passenger_set_cgi_param HTTP_X_FORWARDED_PROTO https;
The nginx directive passenger_set_cgi_param has been replaced by passenger_set_env. nginx指令passenger_set_cgi_param已被passenger_set_env取代。 https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerEnvVar
https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerEnvVar
for newer nginx the directive should be 对于较新的nginx,指令应该是
passenger_set_cgi_param HTTP_X_FORWARDED_PROTO https;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.