Назад | Перейти на главную страницу

Включить один сценарий CGI для Apache в корне документа?

Можно ли включить один сценарий CGI, хранящийся в корне документа Apache 2.4?

Я надеялся, что возможно следующее:

<VirtualHost *:80>
    DocumentRoot "PATH/TO/htdocs/localhost"
    ServerName localhost
    ErrorLog "logs/localhost/errors.log"
    CustomLog "logs/localhost/access.log" common

    ScriptAlias "/python/" "PATH/TO/htdocs/localhost/python/index.py"
    <Files "PATH/TO/htdocs/localhost/python/index.py">
      Options +ExecCGI
      AddHandler cgi-script .py
      Require all granted
    </Files>
</VirtualHost>

ИЛИ я действительно должен помещать это в CGI-bin?

Apache действительно не рекомендует размещать скрипты в htdocs. В моем случае это резервный виртуальный хост на локальной машине разработки, поэтому я могу обойтись следующим:

PATH/TO/htdocs/localhost/index.html
PATH/TO/scripts/localhost/index.py

Указание DirectoryIndex указывает мое предпочтение файлу python над статическим файлом html. Затем первый переехал в новое место, как указано выше.

<VirtualHost *:80>
    DocumentRoot "PATH/TO/htdocs/localhost"
    ServerName localhost
    ErrorLog "logs/localhost/errors.log"
    CustomLog "logs/localhost/access.log" common

    DirectoryIndex index.py index.php index.html

    ScriptAlias "/python/" "PATH/TO/scripts/localhost/python/index.py"
    <Files "PATH/TO/scripts/localhost/python/index.py">
      Options +ExecCGI
      AddHandler cgi-script .py
      Require all granted
    </Files>
</VirtualHost>