在Apache服务器上运行Python脚本:403禁止的错误

我需要在运行Ubuntu的AWS EC2实例上使用Apache设置的网站子域上运行一些python脚本。 我试着按照这篇文章中提到的一些步骤。 在尝试访问子域时,出现了403错误(“禁止访问。您无权访问此服务器上的/index.py”)。

我在index.py文件上有755(-rwxr-xr-x)权限。

subdomain.website.com.conf文件:

<VirtualHost *:80> ServerAdmin [email protected] ServerName subdomain.website.com DocumentRoot /var/www/html/subdomain.website.com/public_html Options +ExecCGI DirectoryIndex index.py AddHandler cgi-script .py </VirtualHost> 

我的错!

指令OptionsDirectoryIndex需要位于Directory标签内。

正确的subdomain.website.com.conf文件:

 <VirtualHost *:80> ServerAdmin [email protected] ServerName subdomain.website.com DocumentRoot /var/www/html/subdomain.website.com/public_html <Directory /var/www/html/subdomain.website.com/public_html> Options +ExecCGI DirectoryIndex index.py </Directory> AddHandler cgi-script .py </VirtualHost>