【发布时间】:2014-10-02 00:34:16
【问题描述】:
我需要以下重定向示例的帮助,使用 NGINX:
- http://example.com 必须重定向到 https://www.example.com
- http://www.example.com 必须重定向到 https://www.example.com
- https://example.com 必须重定向到 https://www.example.com
我已阅读 related questions 但仍然无法让两个重定向一起工作。
我已尝试过此配置,但在尝试加载站点时出现错误:连接中断。
# Redirect any http:// request to https://www.example.com
server {
listen 80;
return 301 https://www.example.com$request_uri;
}
# Redirect http://example.com to https://www.example.com
server {
listen 443 ssl;
server_name example.com
return 301 https://www.example.com$request_uri;
}
server {
listen 443;
server_name www.example.com;
ssl on;
ssl_certificate /foo.crt;
ssl_certificate_key /foo.key;
root /foo/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
【问题讨论】: