Apache2配置访问目录

OS版本:Debian 12
Apache2版本:Apache/2.4.57 (Debian)

  1. /etc/apache2/ports.conf中添加自定义端口xxxxx
Listen xxxxx
  1. /etc/apache2/apache2.conf中添加允许自定义访问目录/any/path
<Directory /any/path>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
  1. /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>
  1. 修改/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
  1. 重启Apache2服务
sudo systemctl restart apache2.service
  1. 验证访问正确性,访问localhost:xxxxx验证
posted @ 2023-06-07 09:24  dwr2001  阅读(631)  评论(0)    收藏  举报