用户登录www,但不登录非www

时间:2017-07-22 22:39:09

标签: nginx dns

我遇到一个问题,如果用户从www.domain.com登录该站点,然后转到domain.com(没有www),则它们不会显示为已登录。如果他们返回到www.domain.com,他们已登录。

为什么会这样?

我最近通过以下教程在我的服务器上设置了SSL:

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

我还将域名的DNS值更改为指向我的服务器。我有一个domain.com和www.domain的A记录,它指向我服务器的弹性IP。

这是我的nginx配置:

# Cache expires
map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   max;
    application/javascript     max;
    ~image/                    max;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    expires $expires;

    server_name domain.com www.domain.com;
    return 301 https://$server_name$request_uri;
}

server {
    # SSL configuration

    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    expires $expires;

    include snippets/ssl-domain.com.conf;
    include snippets/ssl-params.conf;

    root /var/www/html/public;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name domain.com www.domain.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)\$;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~ /.well-known {
                allow all;
        }
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

这听起来像你的会话有问题,你是否试图将你的sessioncookie的域设置为www和非www?