无法在Laravel Forge上使用Nginx将http://example.com重定向到https://www.example.com

时间:2019-01-29 21:37:50

标签: nginx nginx-config laravel-forge

我正在Laravel Forge上尝试将non-ssl和non-www的每种组合重定向到ssl和www。

http://www.example.com-> https://www.example.com有效

https://example.com-> https://www.example.com有效

但是

http://example.com由于ERR_EMPTY_RESPONSE超时。

这是我的nginx conf文件:

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

    server_name example.com *.example.com;
    return 301 https://$host$request_uri;
}

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

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


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com www.example.com *.example.com;
    root /home/forge/www.example.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/www.example.com/382594/server.crt;
    ssl_certificate_key /etc/nginx/ssl/www.example.com/382594/server.key;

    ssl_protocols TLSv1.2;

    (...other certificate and rewrite directives)

}

我出于绝望地添加了_ server_name,但是它仍然无法捕获http://example.com。这里是否有任何明显的错误,还是应该在其他地方查看?

0 个答案:

没有答案