我在nginx服务器上设置了一个电子商务域,它应该满足以下条件:
使用下面显示的配置,based on this SO answer追求相反的情况,即强制所有流量到https://domain.com而没有www,我得到以下结果:
如何将https://domain.com重定向到https://www.domain.com?检查我当前的配置:
#
# Rewrite any http requests for DOMAIN.com to www.DOMAIN.com using SSL
#
server {
listen 80;
server_name DOMAIN.com;
return 301 https://www.DOMAIN.com$request_uri;
}
#
# Rewrite any http requests for www.DOMAIN.com to https
#
server {
listen 80;
server_name www.DOMAIN.com;
return 301 https://www.DOMAIN.com$request_uri;
}
#
# The DOMAIN.com website
#
server {
listen 443 default_server;
server_name DOMAIN.com;
root /var/www;
index index.html index.htm index.php;
ssl on;
ssl_certificate /etc/nginx/ssl/www_DOMAIN_com.pem;
ssl_certificate_key /etc/nginx/ssl/www_DOMAIN_com.key;
ssl_session_timeout 5m;
if ($host = DOMAIN.com) {
rewrite ^(.*) https://www.DOMAIN.com:443$request_uri? permanent;
}
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_session_cache shared:SSL:10m;
location / {
try_files $uri $uri/ @handler;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location @handler {
rewrite / /index.php;
}
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
}
答案 0 :(得分:2)
443 DOMAIN.com块上缺少ssl指令。您当然必须拥有DOMAIN.com的有效证书
答案 1 :(得分:0)
(代表OP发布)。
以上配置有效,问题实际上是在DNS设置中。