Apache giving 403 forbidden errors

后端 未结 8 1973
终归单人心
终归单人心 2020-11-29 05:06

Ok, so i\'ve previously set up two virtual hosts and they are working cool. they both house simple web projects and work fine with http://project1 and htt

8条回答
  •  悲哀的现实
    2020-11-29 05:33

    Notice that another issue that might be causing this is that, the "FollowSymLinks" option of a parent directory might have been mistakenly overwritten by the options of your project's directory. This was the case for me and made me pull my hair until I found out the cause!

    Here's an example of such a mistake:

    
            Options FollowSymLinks
            AllowOverride all
            Require all denied
    
    
    
            Options Indexes # <--- NOT OK! It's overwriting the above option of the "/" directory.
            AllowOverride all
            Require all granted
    
    

    So now if you check the Apache's log message(tail -n 50 -f /var/www/html/{the_error_log_file_of_your_site}) you'll see such an error:

    Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive
    is also forbidden due to its similar ability to circumvent directory restrictions
    

    That's because Indexes in the above rules for /var/www directory is overwriting the FolowSymLinks of the / directory. So now that you know the cause, in order to fix it, you can do many things depending on your need. For instance:

    
            Options FollowSymLinks
            AllowOverride all
            Require all denied
    
    
    
            Options FollowSymLinks Indexes # <--- OK.
            AllowOverride all
            Require all granted
    
    

    Or even this:

    
            Options FollowSymLinks
            AllowOverride all
            Require all denied
    
    
    
            Options -Indexes # <--- OK as well! It will NOT cause an overwrite.
            AllowOverride all
            Require all granted
    
    

    The example above will not cause the overwrite issue, because in Apache, if an option is "+" it will overwrite the "+"s only, and if it's a "-", it will overwrite the "-"s... (Don't ask me for a reference on that though, it's just my interpretation of an Apache's error message(checked through journalctl -xe) which says: Either all Options must start with + or -, or no Option may. when an option has a sign, but another one doesn't(E.g., FollowSymLinks -Indexes). So it's my personal conclusion -thus should be taken with a grain of salt- that if I've used -Indexes as the option, that will be considered as a whole distinct set of options by the Apache from the other option in the "/" which doesn't have any signs on it, and so no annoying rewrites will occur in the end, which I could successfully confirm by the above rules in a project directory of my own).

    Hope that this will help you pull much less of your hair! :)

提交回复
热议问题