为什么 nginx 不重定向 root 请求?
why isn't nginx redirecting root requests?
我有一个 100% SSL 的 rails 应用程序,我正在尝试让 nginx 将所有请求重定向到 https,我不确定 rails 或 nginx 中是否存在配置错误。
config/environments/production.rb 设置为:
config.force_ssl = true
尝试 1:
server {
server_name 192.168.2.4;
listen 80;
listen 443 ssl;
. . .
}
尝试 2:
server {
server_name 192.168.2.4;
listen 80;
return 301 https://192.168.2.4$request_uri;
}
server {
server_name 192.168.2.4;
listen 443 ssl;
. . .
}
在这两种情况下 http://192.168.2.4 will show the nginx welcome page, yet http://192.168.2.4/login will correctly redirect to https://192.168.2.4/login
添加ssl on;
到server { }
块。
您还可以 link 通过 ssl_certificate
和 ssl_certificate_key
获取 ssl 证书。
我有一个 100% SSL 的 rails 应用程序,我正在尝试让 nginx 将所有请求重定向到 https,我不确定 rails 或 nginx 中是否存在配置错误。
config/environments/production.rb 设置为:
config.force_ssl = true
尝试 1:
server {
server_name 192.168.2.4;
listen 80;
listen 443 ssl;
. . .
}
尝试 2:
server {
server_name 192.168.2.4;
listen 80;
return 301 https://192.168.2.4$request_uri;
}
server {
server_name 192.168.2.4;
listen 443 ssl;
. . .
}
在这两种情况下 http://192.168.2.4 will show the nginx welcome page, yet http://192.168.2.4/login will correctly redirect to https://192.168.2.4/login
添加ssl on;
到server { }
块。
您还可以 link 通过 ssl_certificate
和 ssl_certificate_key
获取 ssl 证书。