Reputation: 81
I am using Laravel 7 and website is running on https but it shows all links to http.
i am using below code to redirect for all pages.
<a href="{{url('about')}}">About></a>
Upvotes: 3
Views: 5404
Reputation: 1
@V-E-Y is right. The better way to enforce HTTPS in Laravel when using Nginx is by configuring the headers like this:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Upvotes: 0
Reputation: 72
I am testing telegram bot with ngrok forwarding, and always edit APP_URL
in my env file
and sometimes I testing local http://localhost:81
My solution in the boot()
method of the AppServiceProvider
use Illuminate\Support\Facades\URL;
if (mb_strpos(env('APP_URL'), 'https') === 0) {
URL::forceScheme('https');
}
Upvotes: 0
Reputation: 327
Hey all who use NGINX proxy
Don't use URL::forceScheme('https');
Just add: proxy_set_header X-Forwarded-Proto $scheme;
location / {
...
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
Upvotes: -1
Reputation: 59
I had the same issue when running a Laravel application behind an NGINX proxy and the communication internally was running via HTTP. So, the request reached Laravel as HTTP.
The solution from Alberto was fixing it. Here is the code I have added to the boot()
method of the AppServiceProvider
:
if (config('app.env') === 'production' || config('app.env') === 'staging') {
URL::forceScheme('https');
}
Upvotes: 4
Reputation: 12949
in config/app.php
you should have a url
entry to set like:
'url' => 'https://your-website.domain'
otherwise you can use the boot
method of AppServiceProvider
adding this:
\URL::forceScheme('https');
Upvotes: 6