Discover Centmin Mod today
Register Now

PHP-FPM Nginx Custom PHP Error Pages

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Bubbles, Mar 1, 2015.

Tags:
  1. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    I've been attempting to set this up for a while, if I try to set it up, I just get a blank page. Here's what I put inside the server block for the virtual host.
    Code:
    error_page 403 /blocked.html;
    
    location = /blocked.html {
        root /home/nginx/domains/mysite/public/;
        internal;
        allow all;
    
    }
    Now the above works fine, but I actually need it to be a PHP page and not HTML. When I change it to .php, I get a chrome error when visiting the 403.
    [​IMG]

     
  2. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    6:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    For Centmin Mod, you might need include /usr/local/nginx/conf/php.conf in the location context

    Code:
    error_page 403 /blocked.php;
    
    location = /blocked.php {
        root /home/nginx/domains/mysite/public/;
        include /usr/local/nginx/conf/php.conf;
        internal;
        allow all;
    
    }
     
  3. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    Code:
    nginx: [emerg] location "\.php$" cannot be inside the exact location "/blocked.php" in /usr
    /local/nginx/conf/php.conf:1
     
  4. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    6:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    doh !

    can you post the full Nginx vhost for your domain in CODE tags
     
  5. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    Code:
    server {
    listen   443 default ssl;
    listen   80;
    server_name mysite.com [URL='http://www.mysite.com;']www.mysite.com;[/URL]
    
    
    error_page 403 /blocked.php;
    
    location = /blocked.php {
        root /home/nginx/domains/mysite.com/public/;
        include /usr/local/nginx/conf/php.conf;
        internal;
        allow all;
    
    }
    
    
    
    ssl on;
    ssl_certificate /usr/local/nginx/ssl/mysite.com.crt;
    ssl_certificate_key /usr/local/nginx/ssl/mysite.com.key;
    
    if ($ssl_protocol = "") {
        rewrite ^/(.*) [URL]https://$server_name/$1[/URL] permanent;
    }
    
    
    error_page  403 = /home/nginx/domains/mysite.com/public/blocked.php;
    
    
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    
    root /home/nginx/domains/mysite.com.com/public;
    
    location / {
    
        include /usr/local/nginx/conf/block.conf;
    
    }
    
    include /usr/local/nginx/conf/staticfiles.conf;
    include /usr/local/nginx/conf/php.conf;
    include /usr/local/nginx/conf/drop.conf;
    include /usr/local/nginx/conf/errorpage.conf;
    }
    
     
  6. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    6:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    remove the php.conf include i suggested

    and you have error_page 403 = defined twice in your vhost
     
  7. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    Still getting that chrome error.
     
  8. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    6:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    had a look at this and best way for php file based 403 is just remove location context match totally and just use

    Code:
    error_page 403 = /blocked.php;
     
  9. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    Default error page when i do that.
     
  10. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    6:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    remove any duplicates in your nginx vhost you may have

    i tested it and works for me :)
     
  11. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    Nope, still doesn't work for me. Removed any other trace of error_page that I could find.
     
  12. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    6:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    restart nginx and php-fpm services ? clear browser cache ?

    should work
     
  13. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    Code:
    Gracefully shutting down php-fpm . done
    Starting php-fpm Failed loading /usr/local/lib/php/extensions/no-debug-non-zts-20100525/ion
    cube_loader_lin_5.4.so:  /usr/local/lib/php/extensions/no-debug-non-zts-20100525/ioncube_lo
    ader_lin_5.4.so: cannot open shared object file: No such file or directory
    [09-Mar-2015 03:38:30] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynam
    ic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/php_curl.dll' - /usr/lo
    cal/lib/php/extensions/no-debug-non-zts-20100525/php_curl.dll: cannot open shared object fi
    le: No such file or directory in Unknown on line 0
    [09-Mar-2015 03:38:30] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynam
    ic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/php_openssl.dll' - /usr
    /local/lib/php/extensions/no-debug-non-zts-20100525/php_openssl.dll: cannot open shared obj
    ect file: No such file or directory in Unknown on line 0
    [09-Mar-2015 03:38:30] NOTICE: PHP message: PHP Warning:  PHP Startup: apc: Unable to initi
    alize module
    Module compiled with module API=20090626
    PHP    compiled with module API=20100525
    These options need to match
    in Unknown on line 0
    done
     
  14. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    And it doesn't work anyway
     
  15. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    6:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    hmm php_curl.dll & php_openssl.dll is a windows file shouldn't be trying to load that.. what modifications or changes to PHP-FPM have you done ?

    ioncube_loader ? you specifically installed or ? what method of install ?

    remove all the extra lines you added to php.ini or respective *.ini files and then run centmin.sh menu option to reinstall APC Cache

    or if this a test VPS, you can do a fresh reload of CentOS 6.6 and new Centmin Mod install :)
     
  16. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    I haven't modified anything apart from the ioncube_loader which is required. Location of php.ini?
     
  17. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    6:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    file locations for php.ini and how .ini files are setup PHP Opcode and Memcached statistics pages | Centmin Mod Community

    or type php --ini in SSH window

    Code:
    php --ini
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    Scan for additional .ini files in: /etc/centminmod/php.d
    Additional .ini files parsed:      /etc/centminmod/php.d/apc.ini,
    /etc/centminmod/php.d/igbinary.ini,
    /etc/centminmod/php.d/imagick.ini,
    /etc/centminmod/php.d/memcache.ini,
    /etc/centminmod/php.d/memcached.ini
    or FAQ item 16 Centmin Mod FAQ - Menu based Nginx installer
     
  18. Bubbles

    Bubbles New Member

    18
    2
    3
    Mar 1, 2015
    Ratings:
    +2
    Local Time:
    6:24 AM
    This truly is odd, i'm still getting the default error.