闲言杂记

前言

caddy是一个轻量的服务器,而且部署起来也不是非常复杂,一向尝鲜的我们安装caddy就是为了尝试下http3和quic,当然caddy作为一些小内存的服务器或者反代其实也是不错的,因为是go编写,所以需要安装环境。

配置环境

apt-get update -y
apt-get install -y gcc g++ make zip 
lrzsz autoconf curl libxml2 libxml2- 
dev libssl-dev bzip2 libbz2-dev 
libjpeg-dev libpng12-dev libfreetype6- 
dev libgmp-dev libmcrypt-dev 
libreadline6-dev libsnmp-dev libxslt1- 
dev libcurl4-openssl-dev
groupadd -r php
groupadd -r www
useradd -r -g php -s /bin/false -d 
/usr/local/php -M php
useradd -r -g www -s /bin/false -d 
/usr/local/www -M www
#安装必要的依赖文件和创建PHP运行用户组

安装php-fpm

mkdir php
cd php
wget 
http://am1.php.net/distributions/php- 
7.2.8.tar.gz
tar -zxf php-7.2.8.tar.gz
cd php-7.2.8
ossl=`find / -name libssl.so`
ln -s $ossl /usr/lib
./configure –prefix=/usr/local/php – 
exec-prefix=/usr/local/php – 
bindir=/usr/local/php/bin – 
sbindir=/usr/local/php/sbin – 
includedir=/usr/local/php/include – 
libdir=/usr/local/php/lib/php – 
mandir=/usr/local/php/php/man –with- 
config-file-path=/usr/local/php/etc – 
with-mysql- 
sock=/var/run/mysql/mysql.sock –with- 
mhash –with-openssl –with- 
mysqli=shared,mysqlnd –with-pdo- 
mysql=shared,mysqlnd –with-gd –with- 
iconv –with-zlib –enable-zip –enable- 
inline-optimization –disable-debug – 
disable-rpath –enable-shared –enable- 
xml –enable-bcmath –enable-shmop – 
enable-sysvsem –enable-mbregex – 
enable-mbstring –enable-ftp –enable- 
pcntl –enable-sockets –with-xmlrpc – 
enable-soap –without-pear –with- 
gettext –  enable-session –with-curl – 
with-jpeg-dir –with-freetype-dir – 
enable-opcache –enable-fpm –with-fpm- 
user=php –with-fpm-group=php –without- 
gdbm –disable-fileinfo
make && make install

/etc/profile 中增加以下行

export PHP_HOME=/usr/local/php
export PATH=$PHP_HOME/bin:$PATH


source /etc/profile
cp sapi/fpm/init.d.php-fpm 
/usr/local/bin/php-fpm
chmod +x /usr/local/bin/php-fpm
cp php.ini-production 
/usr/local/php/etc/php.ini
cp /usr/local/php/etc/php- 
fpm.conf.default 
/usr/local/php/etc/php-fpm.conf

创建进程池

/usr/local/php/etc/php-fpm.d/www.conf

; Start a new pool named ‘www’
[www]
listen = /usr/local/php/var/run/$pool- 
php-fpm.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0660
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
pm.status_path = /status
ping.path = /ping
ping.response = pong
request_terminate_timeout = 100
request_slowlog_timeout = 10s
slowlog = 
/usr/local/php/var/log/$pool.log.slow
“

启动php

/usr/local/bin/php-fpm start

安装caddy

curl https://getcaddy.com | bash -s 
personal http.cgi,http.filemanager

创建网站文件夹

 mkdir -p /data/www/default
 chown -R www:www /data/www/

创建配置文件-实例

 http://localhost {
 root /data/www/default
 gzip
 fastcgi / /usr/local/php/var/run/www- 
 php-fpm.sock {
 ext .php
 split .php
 index index.php
 }


后台运行 Caddy

nohup caddy -conf=/etc/caddy.conf >>  
/usr/local/caddy.log 2>&1 &

后记

caddy尝鲜支持quic和新特性 但是本身性能其实不如nginx,作为轻量服务器也是不错的。

Comment

This is just a placeholder img.