Laravel 5和Cloudflare SSL
今天,我第一次决定在我的web项目上使用Laravel 5和Cloudflare SSL,laravel,ssl,nginx,laravel-5.1,cloudflare,Laravel,Ssl,Nginx,Laravel 5.1,Cloudflare,今天,我第一次决定在我的web项目上使用ssl。首先,我在cloudflare.com中配置了我的域。然后我打开cloudflare中的页面规则,自动将网站重定向到https http://*example.com/* 为了确保它能正常工作,我将simpleindex.php添加到了public\uhtml中,它成功了。我的意思是,当我进入该网站时,https处于活动状态,该网站向我显示了一个著名的词:“Hello World” 之后,我将我的Laravel项目上传到web服务器并配置了虚拟主
ssl
。首先,我在cloudflare.com中配置了我的域。然后我打开cloudflare中的页面规则,自动将网站重定向到https
http://*example.com/*
为了确保它能正常工作,我将simpleindex.php
添加到了public\uhtml中,它成功了。我的意思是,当我进入该网站时,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
上运行良好
我尝试使用listen443
配置服务器,使用ssl on
命令,但没有任何结果
此外,我还发现了有关laravel 5的cloudflare的链接。但不确定,这就是我想要的
如有任何帮助,将不胜感激。解决方案 强制所有路由到
https
我决定制作一个中间件,并在所有路由中使用它
namespace App\Http\Middleware;
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);
}
}