我有一个rails 4 beta的网站.它在Nginx + Unicorn上运行.我希望nginx将请求协议('http'或'https')转发给unicorn,以便我可以使用它们.但是我无法使其发挥作用.
我把<%= request.ssl? %>和<%= request.protocol %>在测试视图文件.我的nginx服务器配置文件如下:
upstream unicorn {
server unix:/tmp/unicorn.blog.sock fail_timeout=0;
}
server {
listen 80;
listen 443;
server_name example.com;
root /home/example;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-Proto https; # <--- Line 1
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Ssl on; # <--- Line 2
proxy_redirect off;
proxy_pass http://unicorn; …Run Code Online (Sandbox Code Playgroud)