4760
systemd常用服务开机启动配置
乐果 发表于 2019 年 04 月 13 日 标签:PHPnginxcaddy
由于ubuntu18.04开始,系统的开机启动配置不再使用/etr/rc.local,改用systemd方式.
现总结lnmp中常见的服务配置如下:
nginx
vim /lib/systemd/system/nginx.service
编辑nginx.service文件如下
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/data/service/tengine/logs/nginx.pid
ExecStartPre=/data/service/tengine/sbin/nginx -t
ExecStart=/data/service/tengine/sbin/nginx
ExecReload=/data/service/tengine/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
授权/重启服务载入配置/测试/加入开机启动,如下:
chmod +x /lib/systemd/system/nginx.service
systemctl daemon-reload
systemctl start nginx.service
systemctl reload nginx.service
systemctl stop nginx.service
systemctl enable nginx.service
php
vim /lib/systemd/system/php73.service
编辑php73.service文件如下
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/data/service/php73/var/run/php-fpm.pid
ExecStart=/data/service/php73/sbin/php-fpm --nodaemonize --fpm-config /data/service/php73/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
授权/重启服务载入配置/测试/加入开机启动,如上nginx类似~
debian11
安装 caddy:
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-xcaddy.list
apt update
apt install caddy
systemctl enable caddy
systemctl start caddy
配置文件在: /etc/caddy/Caddyfile
常见配置格式,例如:
{
http_port 8080
https_port 443
}
www.xiaotangren.cc:443 {
reverse_proxy 47.110.147.31:80 {
header_up Host "xiao.edge.papa.com.cn"
}
tls 89907749@qq.com
}
xiaotangren.cc:443 {
reverse_proxy 23.254.224.105:9090 {
header_up Host "xiaotangren.edge.xiaotangren.cc"
}
tls unphps@gmail.com
}