Apache2配置访问目录
OS版本:
Debian 12
Apache2版本:Apache/2.4.57 (Debian)
- 在
/etc/apache2/ports.conf中添加自定义端口xxxxx
Listen xxxxx
- 在
/etc/apache2/apache2.conf中添加允许自定义访问目录/any/path
<Directory /any/path>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
- 在
/etc/apache2/sites-enabled/000-default.conf中添加对应端口虚拟主机
<VirtualHost *:xxxxx> # 自定义端口xxxxx
ServerAdmin webmaster@localhost
DocumentRoot /any/path # 自定义目录/any/path
ErrorLog ${APACHE_LOG_DIR}/error-xxxxx.log # 自定义错误日志
CustomLog ${APACHE_LOG_DIR}/access-xxxxx.log combined # 自定义访问日志
</VirtualHost>
- 修改
/any/path的访问权限
由于Apache2使用www-data:www-data进行访问,因此为了正常访问,请为该用户(组)赋予读写(执行)权限
sudo usermod -a -G <group> www-data
sudo chmod 775 -R /any/path
sudo chmod 775 -R /any
- 重启
Apache2服务
sudo systemctl restart apache2.service
- 验证访问正确性,访问
localhost:xxxxx验证

浙公网安备 33010602011771号