5.2 https

http://laravel.com/

http://kejyun.github.io/Laravel-4-Docum ... roduction/
回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

5.2 https

文章 yehlu »

http://www.jeffmould.com/2016/01/31/lar ... using-ssl/

Laravel 5.2 – Forcing HTTPS Routes when using SSL
January 31, 2016 by Jeff Mould 23 Comments

There is an increasing push for privacy and security on the web and a lot of this starts with sites using SSL to encrypt their traffic. With SSL certificates now free from companies like Amazon recently launching their AWS Certificate Manager and initiatives like Let’s Encrypt there really is no reason now that sites should not have SSL.

This article though is not about encryption, installing SSL, or your need for SSL in general. Instead I want to focus on after you have chosen to implement SSL on your site. Particularly if you are using AWS Certificate Manager (ACM) with an Amazon Elastic Load Balancer (ELB) in front of a Laravel 5.2 site. You may like many others choose to keep it simple and have the ELB forward port 443 (HTTPS) to port 80 (HTTP) on your EC2 instance. In this case there you may not have a certificate residing on the EC2 instance(s) and you may not have the EC2 instance configured to handle requests on port 443. If you are using Laravel 5.2 this may present some challenges. Since Laravel 5.2 only sees the HTTP traffic, it builds the links with http instead of with https. This will create problems as you will now have unsecure links being shown on your site.

Luckily the fix for this is fairly simply. You can simply add three lines of code to the AppServiceProvider.php file and presto all your links will now be created using HTTPS instead of HTTP.

代碼: 選擇全部

public function boot()
{
     if (!\App::environment('local')) {
          \URL::forceSchema('https');
     }
}
Update the boot function in \App\Providers\AppServiceProvider.php file with the code above. That’s all there is too it. Laravel 5.2 will now handle the rest and your links will all have HTTPS in front of them.
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Re: 5.2 https

文章 yehlu »

nginx.conf

代碼: 選擇全部

    server {
        listen       80;
        server_name  1.1.1.1;
        root         /usr/share/nginx/html/laravel/public;
        location / {
           try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
        listen       80;
        server_name www.domain.com domain.com;

        return 301 https://www.domain.com$request_uri;
    }

    server {
        # 加入 SSL 設定
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        # 憑證與金鑰的路徑
        ssl_certificate /etc/nginx/ssl/www.domain.com.crt;
        ssl_certificate_key /etc/nginx/ssl/domain.key;

        index        index.php index.html index.htm;
        server_name www.domain.com domain.com;
        root         /usr/share/nginx/html/laravel/public;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
         try_files $uri $uri/ /index.php?$args;
        }

        location /551backend/ {
                root   /var/www/html/551backend/;
                index  index.php index.html index.htm;
                auth_basic "Username and Password are required";
                auth_basic_user_file /path/to/directory/.htpasswd;
        }

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
回覆文章

回到「laravel」