Answer the question
In order to leave comments, you need to log in
Laravel 4.2 and HTTPS, what am I doing wrong?
Greetings dear community,
please tell me what I'm doing wrong:
There is an application on Laravel, the routes work, everything is fine. There was a need to enable https for the site.
I'm using nginx, the host config is:
server {
listen 443 ssl spdy;
server_name server.com;
keepalive_timeout 70;
error_log /var/log/nginx/server-errors.log;
access_log /var/log/nginx/server-access.log;
root /srv/www/server.com/;
index index.php;
ssl on;
ssl_certificate /etc/nginx/ssl/server.com/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.com/server.key;
ssl_dhparam /etc/nginx/ssl/dhparam.pem; ssl_prefer_server_ciphers on; ssl_stapling on; ssl_stapling_verify on;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers kEECDH+AESGCM+AES128:kEECDH+AES128:kRSA+AESGCM+AES128:kRSA+AES128:!RC4:!aNULL:!eNULL:!MD5:!EXPORT:!LOW:!SEED:!CAMELLIA:!IDEA:!PSK :!SRP:!SSLv2;
add_header Content-Security-Policy-Report-Only "default-src https:; script-src https: 'unsafe-eval' 'unsafe-inline'; style-src https: 'unsafe-inline'; img-src https: data :: font-src https: data:; report-uri /csp-report";
resolver 127.0.0.1;
resolver_timeout 10s;
add_header Strict-Transport-Security "max-age=31536000";
location / {
# Front Controller Pattern
# Roundcube doesn't require the query string /index.php?q=$uri&$args, and can read from REQUEST_URI /index.php
try_files $uri $uri/ /index.php;
#auth_basic "Restricted"; #For Basic Auth
#auth_basic_user_file /etc/nginx/.htpasswd; #For Basic Auth
}
# Deny access to the following files
location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ { location ~ /\. { access_log off; log_not_found off;
deny all;
}
# Deny access to the following directories
location ~ ^/(config|temp|logs)/ {
deny all;
}
# Deny access to hidden/important files eg: .htaccess .htpasswd deny all; } location = /favicon.ico { access_log off; log_not_found off; } location ~* \.(?:v|s|css|js|jp?g|gif|png|ico|mp3|wav|swf)$ { expires 1y; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate";
fastcgi_hide_header Set-Cookie;
access_logoff;
}
# Pass the PHP scripts to FastCGI server (locally with unix: param to avoid network overhead)
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Route::get('foo', array('https', function()
{
return 'Must be over HTTPS';
}));
or
Route::group(['before' => 'forceHttps'], function(){
Route::resource('websrv', 'RegistrationAppController');
});
App::before(function($request)
{
if( ! Request::secure() )
{
return Redirect::secure( Request::path() );
}
});
Route::filter('secure', function () {
if (! Request::secure()) {
return Redirect::secure(
Request::path(),
in_array(Request::getMethod(), ['POST' , 'PUT', 'DELETE']) ? 307 : 302
);
}
});
Route::when('*', 'secure');
Route::filter('forceHttps', function($req){
if (! Request::secure()) {
return Redirect::secure(Request::getRequestUri());
}
});
8/Jun/2015:21:15:33 +0200] "GET /foo HTTP/1.1" 404 162 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
Answer the question
In order to leave comments, you need to log in
The error was very banal:
root was not pointing to the public directory of the laravel application
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question