加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Laravel 5和Cloudflare SSL

发布时间:2020-12-13 20:55:07 所属栏目:Nginx 来源:网络整理
导读:好吧,今天我第一次决定在Web项目上使用ssl.首先,我在cloudflare.com中配置了我的域.然后,我在cloudflare中打开页面规则,以自动将网站重定向到https. http://*example.com/* 为了确保它能正常工作,我向public_html添加了简单的index.php并成功了.我的意思是,

好吧,今天我第一次决定在Web项目上使用ssl.首先,我在cloudflare.com中配置了我的域.然后,我在cloudflare中打开页面规则,以自动将网站重定向到https.

http://*example.com/*

为了确保它能正常工作,我向public_html添加了简单的index.php并成功了.我的意思是,当我进入该网站时,https处于活动状态,并且该网站向我显示了一个著名的词:“ Hello World”

之后,我将Laravel项目上传到Web服务器并配置了虚拟主机.我使用nginx服务器.

server {
        listen 80;

        root /home/user/www/example.com/public_html/public;
        index index.php index.html index.htm;

        server_name example.com

        location / {
                try_files $uri $uri/ =404;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
                root /usr/share/nginx/html;
        }

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

好吧,当我使用https进入网站时,Laravel路由不起作用.另外,服务器未读取我的css和js文件.

然后我关闭了cloudflare的页面规则,该站点与http配合良好.

我试图用监听443配置服务器,在命令中使用ssl,但是没有任何结果.

另外,我找到了与laravel 5有关cloudflare的链接.但是不确定,这就是我想要的.

Laravel Cloudflare

任何帮助,将不胜感激.

最佳答案

强制所有路由到https我决定制作一个中间件并在所有路由中使用它.

namespace AppHttpMiddleware;

use Closure;

class HttpsProtocol
{
    public function handle($request,Closure $next)
    {
        $request->setTrustedProxies( [ $request->getClientIp() ] );
        if (!$request->secure()) {
            return redirect()->secure($request->getRequestUri());
        }

        return $next($request);
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读