Welcome to Centmin Mod Community
Register Now

Xenforo Custom error message won't replace XenForo's

Discussion in 'Forum software usage' started by BobbyWibowo, Dec 22, 2016.

  1. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    So yeah, as the title says. I want to replace custom error messages on pages served by XenForo. Be it 404 Not Found, 403 Authorization Required (when someone tries to access page that they don't have the permission to) or even 503 (when you deactivated XenForo from its Admin CP).
    So I have this on mydomain.conf and mydomain.ssl.conf:
    Code:
    error_page 401 /error/401.html;
    error_page 403 /error/403.html;
    error_page 404 /error/404.html;
    error_page 500 /error/500.html;
    error_page 502 /error/502.html;
    # error_page 503 /error/503.html;
    error_page 503 /maintenance/index.html;
    error_page 504 /error/504.html;
    
    location ^~ /error {
      internal;
      alias /home/nginx/domains/endlesshorizon.net/private/error;
    }
    
    location ^~ /maintenance {
      alias /home/nginx/domains/endlesshorizon.net/private/maintenance;
    }
    I don't set internal directive for /maintenance because it requires external images and css files which are served from /maintenance as well, so I "thought" that adding internal directive will prevent access to those external resources (need confirmation?).
    Also, I checked 503include-*.conf files, there you use something like @maintenance. Is that like some kind of magic (variable?) that I can use on my case like @error and @maintenance as well? So that, basically someone can't simply try to access the path from their browser with http://mydomain/error or http://mydomain/maintenance.

    So yeah, anyway, even after I have that on my conf files, it won't replace XenForo's error messages. It works on everywhere else though.
    Also, a few months ago, 403 Authorization Required actually worked on pages that XenForo's users don't have permission into (private forum/thread), but now it doesn't??

    Thanks in advance!!
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
  3. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    that is for site maintenance mode feature in 123.09beta01 https://community.centminmod.com/threads/sitestatus-maintenance-mode.5599/
     
    • Informative Informative x 1
  4. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    Honestly, I can't understand a thing, lmao.
    I checked the returned HTTP error code from pages that's served by XenForo, and it returned 403, 404 or even 503 at the right condition, but Nginx just wouldn't take over with its custom error pages. But it works on any other pages not served by XenForo.
     
  5. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
  6. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    Er, I commented that out from mydomain.conf and mydomain.ssl.conf because I thought it was unnecessary if I had the ones that I wrote on the first post in those confs? Or I thought wrong?
     
  7. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    you can use the syntax from errorpage.conf for ideas for your own
     
  8. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    So, I've moved my custom error page to its own .conf file and here's the content:
    Code:
      error_page 401 /error/401.html;
      error_page 403 /error/403.html;
      error_page 404 /error/404.html;
      error_page 500 /error/500.html;
      error_page 502 /error/502.html;
      # error_page 503 /error/503.html;
      error_page 503 /maintenance/index.html;
      error_page 504 /error/504.html;
    
      location = /error/401.html {
        alias /home/nginx/domains/endlesshorizon.net/private/error/401.html;
        access_log off;
        internal;
      }
    
      location = /error/403.html {
        alias /home/nginx/domains/endlesshorizon.net/private/error/403.html;
        access_log off;
        internal;
      }
    
      location = /error/404.html {
        alias /home/nginx/domains/endlesshorizon.net/private/error/404.html;
        access_log off;
        internal;
      }
    
      location = /error/500.html {
        alias /home/nginx/domains/endlesshorizon.net/private/error/500.html;
        allow all;
        access_log off;
        internal;
      }
    
      location = /error/502.html {
        alias /home/nginx/domains/endlesshorizon.net/private/error/502.html;
        allow all;
        access_log off;
        internal;
      }
    
      location = /error/503.html {
        alias /home/nginx/domains/endlesshorizon.net/private/error/503.html;
        allow all;
        access_log off;
        internal;
      }
    
      location = /error/504.html {
        alias /home/nginx/domains/endlesshorizon.net/private/error/504.html;
        allow all;
        access_log off;
        internal;
      }
    
      location ^~ /maintenance {
        alias /home/nginx/domains/endlesshorizon.net/private/maintenance;
        allow all;
        access_log off;
      }
    I matched everything but 503 one to errorpage.conf just in case. It works on random non-existent files such as:
    https://www.endlesshorizon.net/nonexistent.txt
    https://www.endlesshorizon.net/nonexistent/nonexistent.txt
    But it doesn't work on random non-existent path such as (XenForo takes over):
    https://www.endlesshorizon.net/nonexistent (XenForo takes over and say that the requested path could not be found)
    503 doesn't work on custom PHP file which will only set header code to 503 such as:
    https://www.endlesshorizon.net/test/index.php (it will just appear as a blank page with 503 HTTP error code)
    503 also doesn't work on XenForo while it's inactive (deactivated from XenForo's Admin CP):
    https://www.endlesshorizon.net/ (XenForo takes over and say that the site is under maintenance)
    But it works on location directive which only have return 503; in it:
    https://www.endlesshorizon.net/return503

    Here's my location /, just in case it has anything to do with XenForo taking over everything:
    Code:
    location / {
        # block common exploits, sql injections etc
        include /usr/local/nginx/conf/block.conf;
    
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$uri&$args;
      }
    Also, on the thread you linked about Roland's issue, you said that there were supposed to be a custom error message in this site, and you specifically linked https://community.centminmod.com/test.jpg, but I only see nginx's default 404 page there. Unless you did that intentionally.
     
  9. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    yeah i removed it as the custom 404 page layout is outdated since i changed xf themes

    that's normal as xenforo forum closed mode is actually a 503 site unavailable status mode to guests only but not admins

    you'll probably need to play with it some more seeing as you're doing something different from errorpage.conf method
     
  10. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    I'd think guests would see the custom 503 error page though? Unless, that behavior is also exactly why I only got blank page for:
     
  11. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    they should, that's how my site status maintenance mode works
     
  12. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    you need to add error_page setup to include file for php.conf too
     
    • Like Like x 1
  13. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    AHA!
     
  14. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    Figured that I just had to set fastcgi_intercept_errors to on in php.conf, lol.. Oh well, thanks for your time!
     
    • Like Like x 1
  15. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    yeah it use to be enabled by default but 123.09beta01 update disabled it by default :)
     
    • Like Like x 1
  16. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    So that's why it was working by accident a couple week ago!
     
  17. eva2000

    eva2000 Administrator Staff Member

    30,156
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    10:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    • Like Like x 1
  18. Sunka

    Sunka Active Member

    917
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +388
    Local Time:
    2:10 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    @BobbyWibowo could you write exact step by step to do custom error pages?
     
  19. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    Err, let's see, if you want to simply use Centmin Mod's custom error pages as the base, I recommend to uncomment errorpage.conf from yourdomain.conf and yourdomain.ssl.conf (should be at the very bottom of both conf files, although I'm not sure whether it was disabled or enable by default).
    After that, your probably have to copy all custom error page from /usr/local/nginx/html to your website's root directory? Actually, I'm not really sure about this one.

    On my case, I just replaced the default errorpage.conf with the one I posted here: https://community.centminmod.com/posts/42032/, and then made the custom error pages in the path I specified in the config file. And then I set fastcgi_intercept_errors to on in php.conf so that Nginx will read response code from FastCGI and be able to serve the appropriate error pages to PHP pages (I think that's roughly the use of that directive).
     
    • Like Like x 1
    • Informative Informative x 1
  20. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    7:10 AM
    @eva2000 Help, how do I permanently overwrite the value of fastcgi_intercept_errors in php.conf? Seems like when I update PHP with Centmin Mod, the value will be restored to off.

    edit: Also, is there any method to maintain fastcgi_intercept_errors to on while serving through HTTPS, while letting it off while serving through HTTP?
    I set PageSpeed to directly fetch HTTPS link through its HTTP counterpart by going straight to localhost (I also set the domain config to allow local connection only). XenForo shouldn't return 503 when requesting CSS links (while static content shouldn't be handled by XenForo to begin with) so I don't think PageSpeed will have any issue, but well, just in case.
     
    Last edited: Jan 27, 2017