The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SOLVED default error documents.

Discussion in 'EasyApache' started by Spork Schivago, Nov 28, 2016.

  1. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    Hello,

    I have my domain, we'll pretend it's example.com. When I try going to some place like https://example.com/file_doesn't_exist, I expect to see the default 404 page, but I don't. I see:

    Code:
    Not Found
    The requested URL /file_doesn't_exist was not found on this server.
    
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    
    To me, this is saying Apache couldn't find the 404 error page. I see the ErrorDocument for the 404 is set to 404.shtml and if I put a 404.shtml in my /home/username/public_html directory, sure enough, I'll receive the proper page.

    I'm looking at cPanel though, in the section where I can create custom error pages. I see:
    Code:
    Basic error pages are automatically provided by the web server (Apache). However, if you prefer, you can create a custom error page for any valid HTTP status code beginning in 4 or 5.
    
    Where exactly are these basic error pages stored though? I know I have two locations where the 404.shtml files are:
    Code:
    /usr/local/cpanel/htdocs/404.shtml
    /var/www/html/404.shtml
    
    It appears Apache isn't looking for the default 404.shtml file in either of those directories though. Right now, I just want to use the default error pages that come with Apache without copying them to my public_html directory.

    Any ideas?

    Thanks!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Check to see if a custom "ErrorDocument" entry exists in the .htaccess file within the account's home or public_html directory. If so, you must remove the entry and the custom 404.shtml file within the account to ensure the Apache default 404.shtml is utilized.

    Thank you.
     
    Spork Schivago likes this.
  3. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    The ErrorDocument entry does not exist in the .htaccess file, however, it is set in /etc/apache2/conf.d/includes/errordocument.conf and /etc/apache2/conf/httpd.conf includes that file. In the ErrorDocument.conf file, the 404, for example, is listed as /404.shtml. In Apache's httpd.conf file, I see a DocumentRoot pointing to /var/www/html and that directories has the various shtml files. If I copy those shtml files to the account's public_html directory, it works as expected.

    Is this the expected behavior? I thought there'd be a default directory Apache would be looking for, for these files, besides just the virtual host's DocumentRoot directory. Am I wrong in this?

    If so, is there anyway to have Apache server the normal website files through /home/<myusername>/public_html but have it still use the ErrorDocuments in the /var/www/html directory? I don't want to use symlinks or copy the files. I tried pointing the various ErrorDocument statements to the /var/www/html directory, like ErrorDocument 404 /var/www/html/404.shtml

    but it seems ErrorDocument is expecting a relative path, not an absolute.
     
    #3 Spork Schivago, Nov 29, 2016
    Last edited: Nov 29, 2016
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    This is not the expected behavior if you have no custom ErrorDocument entries defined in the account's .htaccess file (/home/$username/.htaccess or /home/$username/public_html/.htaccess), or with a custom VirtualHost entry for the account. The fact that copying the files to the account's public_html directory resolved the issue suggests there's a custom ErrorDocument entry configured for the account in it's VirtualHost or in one of it's .htaccess files. Could you verify that no custom entries exist for the affected account?

    Thank you.
     
    Spork Schivago likes this.
  5. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    I've grepped the entire /etc/apache2 directory. The only ErrorDocument statements are in the:
    Code:
    /etc/apache2/conf.d/cperror.conf
    /etc/apache2/conf.d/includes/errordocument.conf
    
    files.

    The website is hosted out of the /home/sporkschivago/public_html directory. I've grepped the entire /home/sporkschivago/public_html directory and there is no ErrorDocument at all.

    Even on the old server, the default error documents would never display when I had a website setup, unless I copied the various shtml files to the /home/sporkschivago/public_html directory. Then, they'd work.

    It's as if they're only searching for them in the /home/sporkschivago/public_html directory and nowheres else. I don't think Apache generally looks for a .shtml file. So it seems the /etc/apache2/conf.d/includes/errordocument.conf file is properly setting ErrorDocuments, Apache just can't seem to find them unless they're in the /home/sporkschivago/public_html directory.

    Is there some environmental variable I need to set to tell Apache to look in two places? Or some Apache directive that tells Apache to look for them specifically in a different directory, outside the /home/sporkschivago/public_html directory?
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Did you also check the .htaccess file within the account's home directory (e.g. /home/$username/.htaccess)? If so, could you open a support ticket using the link in my signature so we can take a closer look and determine what's happening?

    Thanks!
     
  7. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    I do not have an .htaccess file in the user's home directory, but even if I did, because the DocumentRoot is set to /home/sporkschivago/public_html, Apache would never access the /home/sporkschivago/.htaccess file, right? It would only look for the /home/sporkschivago/public_html/.htaccess file and the .htaccess file for any sub-directories under the /home/sporkschivago/public_html directory, right?

    I have opened three tickets in the past few days. You don't think they'll get mad if I open another ticket? If not, I will open another one. But I don't want to start being a headache, if you know what I mean.
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    It's possible to add custom Apache configuration values to the account's home directory .htaccess file. As an example, when using the "Optimize Website" feature when Mod_Deflate is enabled, it will automatically populate the settings to the .htaccess file in the home directory.

    Also, we're happy to help investigate an issue via a support ticket. A ticket allows us to access the affected system, making it easier to determine what's happening.

    Thanks!
     
    Spork Schivago likes this.
  9. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    Thank you. When I have to play around with my .htaccess file, I've been storing the original in the /home/sporkschivago directory. I guess that's been a horrible idea and might explain why somethings that other people said worked just fine, I couldn't get working (like rewrite rules, for example). I didn't always store the original in the /home/sporkschivago directory, it depended on what I was doing. But boy do I feel stupid! Thanks!
     
  10. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    I started a support ticket a while back but decided to try the BuycPanel.com's support. We had some communication problems in the beginning there and it took a little bit before they could start accessing my servers, but we worked all the kinks out. They ended up escalating this to cPanel. This is the response I got. I believe this is from a cPanel tech. cPanelMichael, could you help me understand what they're saying?

    Code:
    Thanks for holding!
    
    The 404 that is being served is coming in from Apache directly; going back quite a few versions, I determined that this appears to be the functionality there as well, going back even further into EA3, it appears that this happens there as well. Noting, the files references(vs. the error seen) would be specific to the cPanel error documents handled, as we can see they reference here :
    
    root@here [/home/cptestdm/public_html]# cat /var/www/html/404.shtml && echo
    
    
    
    
    
    I was able to implement an Alias directive to allow this to assume the "default" error status with a custom created 404.html in the same location as below:
    
    root@here [/home/cptestdm/public_html]# cat /usr/local/apache/conf/includes/pre_virtualhost_global.conf
    Alias /ourerrors /var/www/html/
    
    root@here [/home/cptestdm/public_html]# grep 404 /usr/local/apache/conf/includes/errordocument.conf
    # 404 - Not Found
    ErrorDocument 404 /ourerrors/404.html
    
    Highest Regards, 
    
    Peter D
    cPanel Certified 
    
    
    I'm confused as to what the answer actually means. Am I supposed to setup an alias in pre_virtualhost_global.conf or something? I'm a bit confused.

    Any thoughts? If not, I'll ask for clarification on the ticket on BuycPanel.com. I just thought maybe because the ticket ended up over here, it'd be best to ask over here. What do you think?

    Thanks.
     
  11. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    It turns out this is the expected behaviour cPanelMichael. I figured out what's going on and got a response from the cPanel technician (although I figured a lot out before he responded).

    /etc/apache2/conf.d/includes/errordocument.conf has all those ErrorDocument <error code> /<error code.shtml> so users can just create a <error code>.shtml file in the cPanel's user's /home/<username>/public_html directory and have the error code display.

    If we comment out those entries in /etc/apache2/conf.d/includes/errordocument.conf, Apache will use the built-in messages, unless there's an ErrorDocument statement in the /etc/apache2/conf.d/cperror.conf file, then it'll pull it from the /var/www/html directory.

    I think is isn't the best design because if the /home/<username>/public_html/<error code>.shtml file doesn't exist, then Apache displays an error after displaying the built-in message:
    Code:
    Additionally, a <error code> error was encountered while trying to use an ErrorDocument to handle the request.
    
    because the <error code>.shtml file does not exist in the /home/<username>/public_html directory.

    I'd think the right way of doing it would be to let users right their own ErrorDocument in an .htaccess file, instead of assuming they're going to be there in the /home/<username>/public_html directory.

    This way, by default, the error pages that are in /var/www/html directory are viewed, but also, users have more control over custom error pages. Right now, if I created a file in the /home/sporkschivago/public_html directory and called it something like 500.shtml, but had it as a real page, I couldn't use that name. It just seems wrong that cPanel purposefully tells Apache to look for files that might or might not be there.

    To remove the Additionally message, I have to comment out all of the lines in the /etc/apache2/conf.d/includes/errordocument.conf file. Is there way to not have that built, ever?
     
    #11 Spork Schivago, Dec 11, 2016
    Last edited: Dec 11, 2016
  12. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    Just so I'm clear, if you comment out the various error codes in /etc/apache2/conf.d/includes/errordocument.conf, Apache will serve the 6 error codes in /var/www/html, and if it's not one of those 6 error codes, it'll fall back to the hard-coded messages in Apache.

    /etc/apache2/conf.d/includes/errordocument.conf appears to have all the error codes. There are lines like
    ErrorDocument 423 /423.shtml

    This is so users can create a 423.shtml in their public_html directory and have Apache display it if they come across a 423.

    Also, now that I have found a way to get Apache to show the various error code documents under the /var/www/html directory on my server (the cPanel ones), am I allowed to edit them? I don't want them showing the cPanel logo. I wanted them to show my domain's logo. Is that allowed or no?

    Thanks!
     
    #12 Spork Schivago, Dec 11, 2016
    Last edited: Dec 11, 2016
  13. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Thank you for updating this thread with the outcome from the support ticket.

    To clarify on your last question, here's the quote from the ticket:

    Also, yes you are allowed to make changes to those error pages to use your own logo.

    Thank you.
     
    Spork Schivago likes this.
  14. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    Thank you! I asked for clarification about editing them and removing the cPanel logo, just to be sure, and they said yes before you answered, but I really appreciate you looking into it for me. I just forgot to update it here.

    I still feel like there's a problem cPanelMichael. From what I was told, the whole purpose of that /etc/apache2/conf.d/includes/errordocument.conf is so people can just put a 404.shtml file (or whatever) in their /home/<username>/public_html directory and have Apache pull it when there's an error. This seems like it's a mistake. The reason I say that, when someone uses cPanel to create custom error documents, doesn't cPanel automatically add the ErrorDocument directive to the .htaccess file? On top of this, if those error documents aren't in the /home/<username>/public_html directory, Apache does throw an error, albeit it's hard to notice.

    If you look through Apache's source code, you see it tests for a variable called recursive_error, and if that variable isn't null, it displays the error message. The source code says the error message is displayed because there was an ErrorDocument directive, but the ErrorDocument could not be found. That's because it doesn't exist.

    To me, it only makes since to not build the /etc/apache2/conf.d/includes/errordocument.conf file at all. Apache will still display the built-in messages when it encounters an error. If people want to create a custom error page, they can do so in cPanel and cPanel will set the appropriate ErrorDocument directive. It just seems like that /etc/apache2/conf.d/includes/errordocument.conf shouldn't be there at all. If anything, maybe the only reason it's there is so the /var/www/html/*.shtml files don't get displayed when there's an error.

    What do you think?
     
  15. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    I did some additional testing, and noted the following behavior:

    1. Created a new account on a test system running cPanel version 60.0.28 with EasyApache 4.
    2. Browsed to /home/$username/public_html and noticed no .htaccess file exists.
    3. Browsed to "cPanel >> Error Pages" and created a custom error page for 404.shtml.
    4. Browsed to /home/$username/public_html and confirmed no .htaccess file exists, and thus no rules were added.
    5. Browsed to /home/$username/public_html and confirmed the 404.shtml file exists.

    Thus, no custom .htaccess entries are added when using the "Error Pages" feature, which is by design as the /etc/apache2/conf.d/includes/errordocument.conf file accounts for this.

    This level of change would require a feature request, as the functionality is currently working as expected (users can upload custom error message pages without the need for .htaccess file modifications). Feel free to submit a feature request for this change, as this is the best avenue for discussions with members of the cPanel Development team regarding how it's implemented and if a change would be viable.

    Thanks!
     
  16. Spork Schivago

    Spork Schivago Well-Known Member

    Joined:
    Jan 21, 2016
    Messages:
    462
    Likes Received:
    52
    Trophy Points:
    28
    Location:
    corning, ny
    cPanel Access Level:
    Root Administrator
    cPanelMichael, for some reason, I thought the .htaccess files were modified whenever a custom error page was created. Perhaps it's best to just keep it the way it is. I dunno how well cPanel admins would feel with their .htaccess files being modified by cPanel. That might cause a stir.

    If I wanted to create a directory called error_pages under /home/<username>/public_html, and store the error document pages there, and then went and added an ErrorDocument statement to my .htaccess file, telling Apache that the various error documents were located in the error_pages directory, do you know if the entries in errordocument.conf would mess with that? I'd think my .htaccess file ErrorDocument directives would take precedence over the Apache configuration file. That's the whole purpose of the .htaccess file, isn't it? So we can override global configuration options?

    Thanks!
     
  17. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Yes, that's correct and should work as expected. Let us know if results in any issues.

    Thanks!
     
    Spork Schivago likes this.
Loading...

Share This Page