教程参考菜鸟教程Python CGI编程,对了这教程里的Cookie那块,expires改一下或者去掉,要不然上面 的2016年早过期了
在PVE下虚拟机里LXC Debian10
apt install apache2
虽然以前也用过apache2,但早就记不得了,好像那时也没改过配置文件,反正现在装的apache2配置文件不是httpd.conf而是apache2.conf,到底是往哪个里填看实际情况吧
配置文件在/etc/apache2/apache2.conf
LoadModule cgid_module /usr/lib/apache2/modules/mod_cgid.so
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
AddHandler cgi-script .cgi .pl .py看Apache HTTP 服务器 2.4 文档CGI 与动态内容里
要LoadModule cgid_module modules/mod_cgid.so
启动找不到模块,搜到了这简简单单的解决方法
sudo mkdir /etc/apache2/modules
sudo cp /usr/lib/apache2/modules/mod_cgid.so /etc/apache2/modules/我就直接用/usr/lib/apache2/modules/mod_cgid.so也不用创建文件夹了
后来又想试试在Nginx下CGI,搜了一堆还是这个简洁Ubuntu Nginx cgi-bin配置使用
apt install nginx
我只想简简单单设置个目录,像上面那样放到目录里,而不是还要在代码里再写
只需要apt install fcgiwrap
vi /etc/nginx/sites-enabled/default
//在第一个server{}里添加
location /cgi-bin/ {
# Disable gzip (it makes scripts feel slower since they have to complete
# before getting gzipped)
gzip off;
# Set the root to /usr/lib (inside this location this means that we are
# giving access to the files under /usr/lib/cgi-bin)
root /var/www;
# Fastcgi socket
fastcgi_pass unix:/var/run/fcgiwrap.socket;
# Fastcgi parameters, include the standard ones
include /etc/nginx/fastcgi_params;
# Adjust non standard parameters (SCRIPT_FILENAME)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
} 之前在apache2可以的现在Nginx也可以了