1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravel11 Sailを開発環境でSSLに対応

Posted at

Valetやパッケージの追加などの方法も紹介されていますが、なんともしっくりこないのでオレオレ証明書を利用してNginxをフロントに配置して対応した。

1. 必要なディレクトリとファイルの作成

mkdir -p ./docker/nginx
touch ./docker/nginx/default.conf
mkdir ./docker/ssl

2. 証明書の作成

mkcert -install
mkcert -key-file ./docker/ssl/localhost-key.pem -cert-file ./docker/ssl/localhost.pem localhost 127.0.0.1 ::1

漢らしくopensslで作るでもいい。

3. docker-compose.ymlの設定

Nginxコンテナ追加

services:
    laravel.nginx:
        image: nginx:1.25
        ports:
            - "${APP_PORT:-80}:80"
            - "${SSL_PORT:-443}:443"
        depends_on:
            - laravel.test
        volumes:
            - .:/var/www/html:ro
            - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
            - ./docker/localhost.pem:/etc/ssl/localhost.pem:ro
            - ./docker/localhost-key.pem:/etc/ssl/localhost-key.pem:ro
        networks:
            - sail
    laravel.test:
		  # ...

4. Nginx設定

server {
    listen 80;
    server_name localhost;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name localhost;

    ssl_certificate /etc/ssl/localhost.pem;
    ssl_certificate_key /etc/ssl/localhost-key.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    root /var/www/html/public;
    index index.php;

    location / {
        proxy_pass http://laravel.test:80;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

5. 起動

./vendor/sail up -d

https://localhost にアクセスして動作を確認。

標準でSSL用意されてるとか、推奨の方法があれば教えてくれ...五飛。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?