惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
博客园 - 司徒正美
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
D
Docker
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
罗磊的独立博客
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
腾讯CDC
T
The Blog of Author Tim Ferriss
小众软件
小众软件
U
Unit 42
T
Tailwind CSS Blog

IT Notes - caddy

IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes IT Notes
IT Notes
Stefano Marinelli · 2022-07-18 · via IT Notes - caddy

Caddy is a great web server. It is easier to configure than nginx and handles the SSL certificates requests and renewals so you don't need to mess with certbot/cron. At times, you might prefer to use Caddy instead of Nginx, Apache, Lighttpd, or other web servers

FreeBSD and Caddy play very well together for static websites/reverse proxies but we often need to serve dynamic websites. To add PHP, follow these steps.

First, install and enable Caddy by running these commands:

pkg install caddy
service caddy enable

Now let's install PHP - let's say PHP 8.3 - and enable php-fpm:

pkg install php83
service php_fpm enable

To use php-fpm, modify the configuration file at /usr/local/etc/php-fpm.d/www.conf by changing the listen address to the following:

Modify

listen = 127.0.0.1:9000

to

listen = /var/run/php83.sock

Then, change the socket owner. Just uncomment the following lines:

listen.owner = www
listen.group = www
listen.mode = 0660

Start php-fpm:

service php_fpm start

Now modify /usr/local/etc/caddy/Caddyfile. Append something like this:

my.website.com {
    root * /usr/local/www/website
    php_fastcgi unix//var/run/php83.sock
    file_server
}

This will configure a virtualhost called my.website.com (and Caddy will try to obtain a certificate for it), with its root on /usr/local/www/website and will process any request to .php files via php socket. The file_server directive ensures that static files can be served from the root path.

Start Caddy:

service caddy start

That's all. While this is a basic configuration, it can be customized for more advanced usage. For example, you can add the following lines to restrict access to certain files:

    @disallowed {
        path /xmlrpc.php
        path *.sql
        path /wp-content/uploads/*.php
    }

    rewrite @disallowed '/index.php'

and you can have a working (and quite safe) Wordpress installation.