版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
# apt install apache2
修改网站根目录(/data为修改的工作目录)
# cd /etc/apache2/
vim apache2.conf
169
170 #<Directory /var/www/>
171 <Directory /data/>
172 Options Indexes FollowSymLinks
173 AllowOverride None
174 Require all granted
175 </Directory>
176

修改虚拟文件访问路径(000-default.conf,也可以自定义虚拟文件)
# vim /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
#DocumentRoot /var/www/html
DocumentRoot /data
PS:DocumentRoot /data为自定义目录
增加 /data 到索引目录,否则出现 AH01630: client denied by server configura
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm /data
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

重新导入apache环境变量,否则会出现 AH00111: Config variable ${APACHE_RUN_DIR} is not defined
# source /etc/apache2/envvars
# systemctl restart apache2