不管怎样,使用 nginx 的通配符 SSL 都会重定向到 www。

不管怎样,使用 nginx 的通配符 SSL 都会重定向到 www。

我们有一个用于 SSL 的服务器设置。以下是 80 和 443 配置。无论我们如何设置 nginx,系统都会自动将 m.domain.com 重定向到 www.m.domain.com。

有人能帮忙吗?我尝试过许多配置和建议,但都无济于事。nginx v1.6.2

SSL

server {
    listen 443 ssl;

    ssl_certificate /etc/ssl/certs/en/<domain>.com.cer;
    ssl_certificate_key /etc/ssl/certs/en/<domain>.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    root /var/www/vhosts/m.<domain>.com/public;
    server_name m.<domain>.com api.<domain>.com;
    access_log /var/log/nginx/m.<domain>.com-access.log;
    error_log /var/log/nginx/m.<domain>.com-error.log;

    location / {
            index index.php;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    # Pass PHP scripts to PHP-FPM
    location ~* \.php$ {
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
            fastcgi_param   LARAVEL_ENV             production;
    }
}

非 SSL

server {
    listen 80;

    server_name m.<domain>.com api.<domain>.com;

    root /var/www/vhosts/m.<domain>.com/public;
    access_log /var/log/nginx/m.<domain>.com-access.log;
    error_log /var/log/nginx/m.<domain>.com-error.log;

    location / {
            index index.php;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    # Pass PHP scripts to PHP-FPM
    location ~* \.php$ {
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
            fastcgi_param   LARAVEL_ENV             production;
    }
}

答案1

我在测试 nginx 上安装了它,一切正常。

  1. 检查你的 PHP 脚本。你可以只添加 phpinfo(); 脚本并将其保存为 phpinfo.php(带有 php 标签)并检查: https://m.domain.com/phpinfo.php

  2. 如果此方法无效,请检查您的 DNS。将以下内容添加到 /etc/hosts:并检查。

  3. 检查您的 htaccess 文件(如果有)。

我的 curl 回应:

curl -I https://m.domain.com --insecure # insecure because I don`t have cert
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Sat, 22 Apr 2017 22:55:11 GMT
Content-Type: text/html
Content-Length: 42
Last-Modified: Sat, 22 Apr 2017 22:50:09 GMT
Connection: keep-alive
ETag: "58fbde21-2a"
Accept-Ranges: bytes

我的测试 nginx 配置:

SSL

server {
    listen 443 ssl;
    ssl_certificate /etc/ssl/domain.com.cer;
    ssl_certificate_key /etc/ssl/domain.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    root /var/www/html/;
    server_name m.domain.com api.domain.com;
    access_log /var/log/nginx/m.domain.com-access.log;
    error_log /var/log/nginx/m.domain.com-error.log;

    location / {
            index index.php index.html;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }
}

无SSL:

server {
    listen 80;

    server_name m.domain.com api.domain.com;

    root /var/www/html;
    access_log /var/log/nginx/m.domain.com-access.log;
    error_log /var/log/nginx/m.domain.com-error.log;

    location / {
            index index.php index.html;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }
}

相关内容