配置 cgi-bin

https://blog.csdn.net/typ2004/article/details/59174162

一个比较全面的教程

注意

配置 cgi-bin 目录权限

1
2
3
4
5
6
7
ScriptAlias /cgi-bin/ /home/sawyer/web/cgi-bin/ # 注意: 这里不可以忽略最后的“/”
<Directory "/home/sawyer/web/cgi-bin/">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Require all granted
        allow from all
</Directory>

启用 cgi 模块

https://blog.csdn.net/a623891391/article/details/47170355

/etc/apache2/mods-available/cgi.load(cgid.load, cgi.conf) 建软件链接到/etc/apache2/mods-enalbed/cgi.load(cgid.load).

  • 注意三个文件缺一不可。

cgi 程序

http://ju.outofmemory.cn/entry/98129

不可忽略 http 头
1
2
print("Content-Type:text/plain;charset=us-ascii\n\n")
print('this is cgi')
  • "Content-Type:text/plain;charset=us-ascii\n\n"
  • 上面这个就是 http 头
  • 注意,最后面的“\n\n”
可执行文件权限 755
1
sudo chmod 755  /dd/test.cgi

Apache 配置文件

/etc/apache2/apache2.conf

配置所有 html 文件目录的权限

/etc/apache2/sites-available/000-default.conf

配置具体网站权限

  • 配置网站目录

    1
    
    DocumentRoot /home/sawyer/web/html

/etc/apache2/conf-enabled/serve-cgi-bin.conf

配置 cgi-bin 目录位置与权限

  • 注意: 目录不能缺少最后的/号