在 Debian 里一般没有叫 copendir 的配置项。你说的可能是下面几种情况之一,我按最常见场景给你说明一下。
Directory / DocumentRoot 配置?很多新手会把 Apache 的目录配置记成 copendir。
sudo apt update
sudo apt install apache2
/var/www/html
编辑配置文件:
sudo nano /etc/apache2/sites-available/000-default.conf
示例:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /data/www
<Directory /data/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
重启 Apache:
sudo systemctl restart apache2
如果你指的是 “能否打开目录列表”,那就是 Indexes:
Options +Indexes # 允许目录浏览
Options -Indexes # 禁止目录浏览
示例:
<Directory /var/www/html/upload>
Options -Indexes
</Directory>
如果你是在写 C 程序:
#include <dirent.h>
#include <stdio.h>
int main() {
DIR *dir = opendir(".");
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
closedir(dir);
}
编译:
gcc test.c -o test
这在 Debian 上不需要额外配置,只要有 build-essential:
sudo apt install build-essential
也可以告诉我你用的是什么服务:
“我是想在 XXX 服务 里配置目录访问 / 打开目录 / 目录浏览”
我可以直接给你精确到 Debian 12 可用的配置。