【发布时间】:2014-06-11 17:24:12
【问题描述】:
我有一个带有 Rails 4 应用程序的 VPS,在 Ubuntu、NginX 和 Unicorn 上运行。
由于我希望对所有页面进行 SSL 加密,因此对 http:// 的所有请求都将转发到 https://,这工作正常。
这是我的 NginX 配置的摘录:
http {
....
server {
listen 80;
server_name example.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
server_name example.com;
root /home/rails/public;
index index.htm index.html;
ssl on;
ssl_certificate /etc/ssl/example.com.crt;
ssl_certificate_key /etc/ssl/example.com.key;
location / {
try_files $uri/index.html $uri.html $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://app_server;
}
}
}
我怎样才能将所有对http://example.com 和https://example.com 的请求转发到https://www.example.com?
感谢您的帮助。
【问题讨论】:
-
我想使用 Rack 中间件可以解决这个问题。检查这个Railscast
标签: ruby-on-rails ssl nginx