【发布时间】:2014-02-23 12:10:30
【问题描述】:
我整天都在与这个问题作斗争。
这是我的nginx.cong:
upstream my_website.co {
server 127.0.0.1:8080;
}
server{
listen 80;
listen 443 default ssl;
# return 301 https://www.my_website.co; - I put it here, but it didn't work
ssl on;
ssl_certificate /etc/nginx/certs/my_website.co.crt;
ssl_certificate_key /etc/nginx/certs/my_website.co.private.key;
server_name my_website.co _;
root /home/deployer/my_website/public;
location / {
proxy_set_header X_FORWARDED_PROTO $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header CLIENT_IP $remote_addr;
if (!-f $request_filename) {
proxy_pass http://my_website.co;
break;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
}
# return 301 https://www.my_website.co; - I put it here, but it didn't work
你能帮我吗,如何将所有内容从http重定向到https?
我的 Rails 代码:
应用控制器
before_filter :ensure_domain
APP_DOMAIN = 'www.my_website.co'
def ensure_domain
if request.env['HTTP_HOST'] != APP_DOMAIN && Rails.env != 'development'
redirect_to "https://#{APP_DOMAIN}#{request.env['REQUEST_PATH']}", :status => 301
end
end
我会感谢每一个帮助,我在这里迷路了。
谢谢
【问题讨论】:
标签: ruby-on-rails ruby http nginx https