Learn about Centmin Mod LEMP Stack today
Become a Member

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:
    7:57 PM
    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

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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:
    7:57 PM
    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

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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:
    7:57 PM
    Done but I still see the default error pages. I tried incognito mode as well.
     
  6. eva2000

    eva2000 Administrator Staff Member

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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:
    7:57 PM
    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

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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:
    7:57 PM
    Yes in virtual.conf and also the 2 confs for my domains.
     
  10. eva2000

    eva2000 Administrator Staff Member

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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;
            }
     
    • Like Like x 1
  11. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    7:57 PM
    That worked. Thanks!
     
    • Like Like x 2
  12. eva2000

    eva2000 Administrator Staff Member

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Awesome :)
     
    • Like Like x 1
  13. rdan

    rdan Premium Member Premium Member

    4,255
    1,034
    113
    May 25, 2014
    Ratings:
    +1,486
    Local Time:
    7:57 AM
    Mainline
    10.2
    • Like Like x 1
  14. eva2000

    eva2000 Administrator Staff Member

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Yup.. static files FTW
     
  15. rdan

    rdan Premium Member Premium Member

    4,255
    1,034
    113
    May 25, 2014
    Ratings:
    +1,486
    Local Time:
    7:57 AM
    Mainline
    10.2
    Another HTTP method use by XenForo is 500 status, so I remove it also :).
     
    • Like Like x 1
  16. eva2000

    eva2000 Administrator Staff Member

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    well if you have 500 internal errors, you have more problems to worry about :)
     
  17. rdan

    rdan Premium Member Premium Member

    4,255
    1,034
    113
    May 25, 2014
    Ratings:
    +1,486
    Local Time:
    7:57 AM
    Mainline
    10.2
    Yeah it's deadlock happens to me when replying on a conversation.
     
  18. eva2000

    eva2000 Administrator Staff Member

    36,039
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    9:57 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Conversation Improvements by Xon | XenForo Community
     
    • Like Like x 1
  19. rdan

    rdan Premium Member Premium Member

    4,255
    1,034
    113
    May 25, 2014
    Ratings:
    +1,486
    Local Time:
    7:57 AM
    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 Premium Member Premium Member

    4,255
    1,034
    113
    May 25, 2014
    Ratings:
    +1,486
    Local Time:
    7:57 AM
    Mainline
    10.2
    I remove 503 also, use when board is closed.
     
    • Like Like x 1
..