【问题标题】:Laravel Forge Redirect Non-www to wwwLaravel Forge 将非 www 重定向到 www
【发布时间】:2017-08-10 08:16:39
【问题描述】:

我有一个 laravel 应用程序,最近 forge 要求所有网站更新他们的letsencrypt SSL证书。

我更新了,这默认了我的 nginx 配置文件,它不再将站点重定向到 www 版本。

这是我的 nginx,谁能看到我做错了什么?

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/domain.co.uk/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name domain.co.uk;
    root /home/forge/domain.co.uk/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/domain.co.uk/##/server.crt;
    ssl_certificate_key /etc/nginx/ssl/domain.co.uk/##/server.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers '##';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/domain.co.uk/server/*;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/domain.co.uk-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/domain.co.uk/after/*;

【问题讨论】:

    标签: php .htaccess ssl nginx laravel-forge


    【解决方案1】:

    不确定您现在是否已经解决了这个问题,但以防万一和/或为了进一步参考,您可以这样做:

    创建(如果不存在):/etc/nginx/conf.d/redirect.conf

    server {
        server_name www.example.com;
        return 301 $scheme://example.com$request_uri;
    }
    

    然后重启nginx。

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-06
      • 1970-01-01
      • 2016-05-13
      • 2019-03-09
      • 2021-08-03
      • 2011-11-05
      • 2011-12-01
      相关资源
      最近更新 更多