繁体   English   中英

Laravel Forge将非www重定向到www

[英]Laravel Forge Redirect Non-www to www

我有一个laravel应用程序,最近伪造请求所有站点续订letencrypt 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/*;

不知道您是否已经解决了这个问题,但是以防万一和/或作为进一步参考,您可以执行以下操作:

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

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

然后重启nginx。

希望能有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM