Welcome to Centmin Mod Community
Register Now

Nginx Custom Error Pages

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by xaitmi, Feb 7, 2015.

  1. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    9:44 AM
    Hi.


    I have 2 different domains running on my VPS right now. I deleted all the default error pages that are in /home/nginx/domains/mysite.com/public like 404.html 500.html etc.

    Right now my 404 pages say this

    404 Not Found
    nginx

    which I'm assuming is the default nginx error page.

    How can I use my own custom error pages across all my domains on the vps.

    I don't want it to say the word nginx in the error pages.
     
  2. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    shouldn't of deleted those 404.html etc, you can recreate them and customise them to match your site design etc.

    then in your Nginx vhost uncomment the include line for errorpage.conf by removing front hash #
    Code:
    #include /usr/local/nginx/conf/errorpage.conf;
    then restart nginx server

    contents of /usr/local/nginx/conf/errorpage.conf
    Code:
             
            error_page 403 /403.html;
            error_page 404 /404.html;
            error_page 500 /500.html;
            error_page 502 /502.html;
            error_page 503 /503.html;
            error_page 504 /504.html;
    
            location = /403.html {
                    access_log              off;
                    internal;
            }
    
            location = /404.html {
                    access_log              off;
                    internal;
            }
    
            location = /500.html {
                    allow                   all;
                    access_log              off;
                    internal;
            }
    
            location = /502.html {
                    allow                   all;
                    access_log              off;
                    internal;
            }
    
            location = /503.html {
                    allow                   all;
                    access_log              off;
                    internal;
            }
    
            location = /504.html {
                    allow                   all;
                    access_log              off;
                    internal;
            }
    
            location = /50x.html {
                    allow                   all;
                    access_log              off;
                    internal;
            }
     
  3. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    9:44 AM
    Thank you.

    But will I have to put those error page files in each of the public folders for my sites?

    I'd prefer to have 1 version of the files in 1 place and it'll be used across all my sites.
     
  4. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    technically you should be able to edit errorpage.conf and define a common path for the following i.e. /usr/local/nginx/html/404.html

    Code:
            error_page 403 /usr/local/nginx/html/403.html;
            error_page 404 /usr/local/nginx/html/404.html;
            error_page 500 /usr/local/nginx/html/500.html;
            error_page 502 /usr/local/nginx/html/502.html;
            error_page 503 /usr/local/nginx/html/503.html;
            error_page 504 /usr/local/nginx/html/504.html;
    
            location = /403.html {
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /404.html {
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /500.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /502.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /503.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /504.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /50x.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
    
     
  5. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    9:44 AM
    Done but I still see the default error pages. I tried incognito mode as well.
     
  6. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Did your restart nginx server and edit /usr/local/nginx/html/404.html ?
     
  7. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    9:44 AM
    Yes i did ngxrestart, and yes I did edit it. I only see the default error pages, not the custom ones you made.

    http://i.imgur.com/Nmk99ig.png

    even though I edited the file paths as you mentioned above.

    My vps has 2 IP's and I have my sites running on one IP if that makes a difference.
     
  8. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    did you remove hash # in front of include file in your vhost .conf ?
    Code:
    include /usr/local/nginx/conf/errorpage.conf;
     
  9. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    9:44 AM
    Yes in virtual.conf and also the 2 confs for my domains.
     
  10. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    i see what the problem is try this for errorpage.conf

    Code:
            error_page 403 /403.html;
            error_page 404 /404.html;
            error_page 500 /500.html;
            error_page 502 /502.html;
            error_page 503 /503.html;
            error_page 504 /504.html;
    
            location = /403.html {
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /404.html {
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /500.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /502.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /503.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /504.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
    
            location = /50x.html {
                    allow                   all;
                    root /usr/local/nginx/html;
                    access_log              off;
                    internal;
            }
     
  11. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    9:44 AM
    That worked. Thanks!
     
  12. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Awesome :)
     
  13. rdan

    rdan Well-Known Member

    5,443
    1,402
    113
    May 25, 2014
    Ratings:
    +2,194
    Local Time:
    10:44 PM
    Mainline
    10.2
  14. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yup.. static files FTW
     
  15. rdan

    rdan Well-Known Member

    5,443
    1,402
    113
    May 25, 2014
    Ratings:
    +2,194
    Local Time:
    10:44 PM
    Mainline
    10.2
    Another HTTP method use by XenForo is 500 status, so I remove it also :).
     
  16. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    well if you have 500 internal errors, you have more problems to worry about :)
     
  17. rdan

    rdan Well-Known Member

    5,443
    1,402
    113
    May 25, 2014
    Ratings:
    +2,194
    Local Time:
    10:44 PM
    Mainline
    10.2
    Yeah it's deadlock happens to me when replying on a conversation.
     
  18. eva2000

    eva2000 Administrator Staff Member

    54,087
    12,177
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,735
    Local Time:
    12:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Conversation Improvements by Xon | XenForo Community
     
  19. rdan

    rdan Well-Known Member

    5,443
    1,402
    113
    May 25, 2014
    Ratings:
    +2,194
    Local Time:
    10:44 PM
    Mainline
    10.2
    Yeah I'm following that thread since early release, But I think it's overkill of what I need.
    I don't want so much features that I don't use much :D.
     
  20. rdan

    rdan Well-Known Member

    5,443
    1,402
    113
    May 25, 2014
    Ratings:
    +2,194
    Local Time:
    10:44 PM
    Mainline
    10.2
    I remove 503 also, use when board is closed.