Nginx配置目录挂载后启动

December 29, 2021

常见情况,使用了一些如NFS,s3fs等方式,动态挂载目录,并提供给nginx使用,如果nginx设置直接启动,会找不到文件因而启动失败。

Fix

Edit systemctl of nginx

# if your device doesn't have /etc/systemd/system/nginx.service.d/
mkdir /etc/systemd/system/nginx.service.d
touch /etc/systemd/system/nginx.service.d/override.conf
# Start edit
vim /etc/systemd/system/nginx.service.d/override.conf
# Or
systemctl edit nginx.service

在文件内添加:

[Unit]
RequiresMountsFor=/data # Your dynamic mount folder

然后重启nginx

systemctl start/restart nginx.service
systemctl enable nginx.service

Copyright © Arcto 2022, Built with Gatsby