0

I have a VirtualHost that I am using to serve requests to files in /var/www/project/src.

I also have a Perl script (CGI binary) that is in /var/www/project/src/cgi-bin/index.pl.

Here's the part of the directive relevant to my question:

<VirtualHost example.com:443>
    ...
    DocumentRoot "/var/www/project/src"
    <Directory "/var/www/project/src">
        Require all granted
        Options +MultiViews +ExecCGI
        AddHandler cgi-script .pl
        DirectoryIndex /cgi-bin/index.pl
    </Directory>
</VirtualHost>

The server starts, but access to the host fails as I get a 403 error.

The Apache logs indicate that the web server cannot find {document-root}/cgi-bin/index.pl:

[Thu Nov 09 11:37:03.578316 2017] [autoindex:error] 
  [pid 122783] [client example-client.com:57203] AH01276: 
  Cannot serve directory /var/www/project/src/: No matching
  DirectoryIndex (/cgi-bin/index.pl) found, and server-
  generated directory index forbidden by Options directive

This directory and index.pl file are in the right location, are owned by the apache user, and have permissions which allow others to read the contents of directories and execute the index.pl CGI-bin.

Moreover, if I change paths in DocumentRoot and Directory variables, the following configuration works:

<VirtualHost example.com:443>
    ...
    DocumentRoot "/"
    <Directory "/">
        Require all granted
        Options +MultiViews +ExecCGI
        AddHandler cgi-script .pl
        DirectoryIndex /var/www/project/src/cgi-bin/index.pl
    </Directory>
</VirtualHost>

Apache starts up, and my access to the host in turn loads /cgi-bin/index.pl, which is rendered correctly.

Question: What would cause the first set of directives to fail, where the second set works?

More specifically: What is preventing the first set of directives from finding /cgi-bin/index.pl in the specified document root, while the second set correctly finds the fully-qualified path /var/www/project/src/cgi-bin/index.pl?

Note: The items in ... do not seem relevant to the issue — whether I remove them, alter them, or leave them, the error and log messages are the same in any case — so I am leaving them out for brevity.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
  • This looks like something better suited to [sf] – pvg Nov 09 '17 at 20:00
  • @pvg not sure of that ;-) – Harry Nov 09 '17 at 20:01
  • @Alex Reynolds i dont think that you do have a directory on your server with this path "/cgi-bin/index.pl". Is your problem maybe about understanding absolute vs relative paths? – Harry Nov 09 '17 at 20:05
  • @Harry that's why there's a [help/on-topic], to enlighten then unsure. – pvg Nov 09 '17 at 20:06
  • @Harry No, I don't believe that is the issue. This is why I set the `Directory` and `DocumentRoot` parameters. See the following for discussion: http://httpd.apache.org/docs/2.0/mod/mod_dir.html#directoryindex – Alex Reynolds Nov 09 '17 at 20:07
  • 2
    I have asked Apache configuration questions on SO many times. https://stackoverflow.com/questions/42600632/access-control-expose-headers-setting-ignored https://stackoverflow.com/questions/41816301/redirecting-both-http-and-https-requests-to-new-host https://stackoverflow.com/questions/21356811/how-to-send-compressed-deflated-svg-via-apache2 etc. I respectfully ask that you please take off-topic concerns to chat. – Alex Reynolds Nov 09 '17 at 20:09

2 Answers2

0

Try changing permissions for /var/www, /var/www/project, /var/www/project/src and/or /var/www/project/src/cgi-bin

Update: Also, don't forget to restart Apache server after making changes.

bislinks
  • 84
  • 10
  • Permissions for parent and children directories are read and executable for others, and read/write/executable for the apache user. – Alex Reynolds Nov 09 '17 at 21:36
0

What's happening is your excessive zeal an excess in your zeal... in the first example, DirectoryIndex /cgi-bin/index.pl points towards your ROOT directory, then searching for a folder caller cgi-bin. This also happens in the second example, but since you give the full path, Apache finds it. Try removing the / before cgi-bin and the issue should fix itself.

Jorge_Freitas
  • 175
  • 1
  • 12
  • I don't think Apache's documentation on DirectoryIndex agrees with you, as it indicates that index files are searched from the root directory. Your advice did not have any effect, in any case. – Alex Reynolds Nov 09 '17 at 21:34