如何在Apache 2.4中为CGI目录启用CORS

经过两天寻找答案,我转向堆栈溢出Apache的主人。

我的CGI文件夹位于/var/www/html/cgi-enabled 。 它承载了一些python脚本,我想执行并返回一个ajax调用JSON 。 我想要在文件夹中的所有脚本都可以访问CORS。

我读过,我需要使用 Header set Access-Control-Allow-Origin "*"命令。 但是,我还没有成功。 请帮我在哪里我应该把命令。

我在Ubuntu 16.04.2上运行apache 2.4.18。

/etc/apache2/看起来像:

 └── apache2.conf ├── conf-available │ └── serve-cgi-bin.conf / conf of .../cgi-enabled ├── conf-enabled │ └── serve-cgi-bin.conf -> ../conf-available/serve-cgi-bin.conf ├── envvars │ └── ... ├── magic │ └── ... ├── mods-available │ └── ... ├── mods-enabled │ └── ... ├── ports.conf ├── sites-available │ ├── 000-default.conf └── sites-enabled └── 000-default.conf -> ../sites-available/000-default.conf 

serve-cgi-bin.conf看起来像:

 <IfModule mod_alias.c> <IfModule mod_cgi.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfModule mod_cgid.c> Define ENABLE_USR_LIB_CGI_BIN <IfDefine ENABLE_USR_LIB_CGI_BIN> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Require all granted </Directory> </IfDefine> <Directory "/var/www/html/cgi-enabled"> Options +ExecCGI SetHandler cgi-script </Directory> </IfModule> 

sites-available/000-default.conf看起来像:

  <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined ServerName localhost ProxyPreserveHost On ProxyPass /test/ws http://127.0.0.1:5100/test ProxyPassReverse /test/ws http://127.0.0.1/test ProxyPass /test http://127.0.0.1:5100/test ProxyPassReverse /test http://127.0.0.1:5100/test <Directory /> Require all granted Options -Indexes </Directory> Alias /static /home/ubuntu/anaconda3/lib/python3.6/site-packages/bokeh/server/static <Directory /home/ubuntu/anaconda3/lib/python3.6/site-packages/bokeh/server/static> #Directives to effect the static directory Options +Indexes </Directory> </VirtualHost>