Having only http
protocol on your local development is enough, but sometimes when your project has to access some service locally, your project has to possess the https
protocol.
If we are using nginx
like in the previous posts, we have to configure the certificate to make it 'https'. So to enable this https
in a fake way in our local development, we could use caddy
instead of nginx
.
Prerequisites
If you haven't use Laradock before, try to set up a simple Laravel project like I did here. Then starting from here, we can use caddy
as an alternative for nginx
.
Configure the Caddy file
You can find the caddy server configuration in caddy\caddy\Caddyfile
file. There are some pre-written examples here, but we will use the actual one for the my-awesome-laravel-app
from the previous post like this:
https://my-awesome-laravel-app.test {
root /var/www/my-awesome-laravel-app/public
fastcgi / php-fpm:9000 php {
index index.php
}
rewrite {
to {path} {path}/ /index.php?{query}
}
gzip
browse
log /var/log/caddy/access.log
errors /var/log/caddy/error.log
tls self_signed
}
Run the containers
If you have nginx
container running, you have to stop it first with:
docker-compose stop nginx
Then, you should able to run caddy and php-fpm container with this command:
docker-compose up -d caddy php-fpm
You may want to set the APP_URL
in the laravel .env
:
APP_URL=https://my-awesome-laravel-app.test
Then you should able to access it on https://my-awesome-laravel-app.test. Although you will get the Not Secure
status next to the address bar like in Chrome browser, you still able to open it in https
.
Have fun exploring caddy!
Top comments (0)