我有一个简单的bash脚本,该脚本应生成Apache site.conf 文件,然后运行a2ensite site.name
一切正常,但是a2ensite不会自动生成日志文件。然后,当我运行sudo systemctl reload apache2
时,它会向我抛出错误无法访问目录'/var/log/apache2/www/site.name /' Bash文件如下:
#!/bin/bash
read -p 'Write url without www and http prefixes: ' url
template=$(</home/Camo/custom-scripts/apache/site-template.conf)
# Next line is string substitution
template=("${template//__URL__/$url}")
configFile=${url}'.conf'
configDirPath="/etc/apache2/sites-available/"
wwwDirPath="/var/www/html/$url"
mkdir $wwwDirPath
chown -R www-data:www-data $wwwDirPath
chmod 644 -R $wwwDirPath
echo "$template" > $configDirPath$configFile
sudo a2ensite ${configFile}
sudo systemctl reload apache2
这是上一个脚本创建的site.cong文件
<VirtualHost *:80>
ServerAdmin xxxxx.xxxxx@gmail.com
ServerName camo.publicvm.com
ErrorLog ${APACHE_LOG_DIR}/www/camo.publicvm.com/error.log
CustomLog ${APACHE_LOG_DIR}/www/camo.publicvm.com/access.log combined
DocumentRoot /var/www/html/camo.publicvm.com
<Directory /var/www/html/camo.publicvm.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
</VirtualHost>
一切正常,那么为什么缺少日志文件?感谢您的帮助。
答案 0 :(得分:1)
日志文件不会自动生成,因此您必须手动创建它们:
Quotation_Mark
不要忘记更改其所有权:
touch ${APACHE_LOG_DIR}/www/camo.publicvm.com/error.log
touch ${APACHE_LOG_DIR}/www/camo.publicvm.com/access.log
然后检查一切是否正常,如果正常,请重新加载chown root.adm ${APACHE_LOG_DIR}/www/camo.publicvm.com/error.log
chown root.adm ${APACHE_LOG_DIR}/www/camo.publicvm.com/access.log
服务:
apache2