Want to subscribe to topics you're interested in?
Become a Member

Nginx Forward users to maintenance.html page and exclude 2-3 static ip's only

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

  1. pamamolf

    pamamolf Well-Known Member

    2,821
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    7:18 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    • CentOS Version: CentOS 7 64bit ?
    • Centmin Mod Version Installed:123.09beta01
    • Nginx Version Installed:1.11.9
    • PHP Version Installed: 5.6.30
    • MariaDB MySQL Version Installed:10.1.21
    • When was last time updated Centmin Mod code base ? : run centmin.sh menu option 23 submenu option 2

    Hello

    How can i forward all my forum users to a maintenance.html page that i have on root and exclude 2-3 static ips only so i can do a big upgrade?

    Thank you
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,956
    6,917
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,418
    Local Time:
    3:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    123.09beta01 out of box has site status maintenance mode https://community.centminmod.com/threads/sitestatus-maintenance-mode.5599/

    contents of include file /usr/local/nginx/conf/maintenance.conf added to /usr/local/nginx/conf/nginx.conf. You can add your own ip to be whitelisted to bypass maintenance mode or even add specific urls that bypass maintenance mode, i.e. images you include in your maintenance.html page.
    Code (Text):
         # IPs you can whitelist from maintenance mode
         geo $maint_whitelist {
              include /usr/local/nginx/conf/sitestatus.conf;
              127.0.0.1 0;
              #YOURIPADDRESS 0;
         }
    
         map $http_host$uri $exclude_url {
              default                                                0;
              "~^newdomain1.com/js/jquery.fittext.js"                1;
              "~^newdomain1.com/blog/js/jquery.fittext.js"           1;
         }
    
         map $maint_whitelist$exclude_url $maintenance {
              default        1;
              10             1;
              11             1;
              00             0;
              01             0;
         }

    The sitestatus command options, just 2 exist - on or off. Off means put site into maintenance mode :)
    Code (Text):
    sitestatus
    /usr/bin/sitestatus {on|off}
    


    should work assuming your nginx vhost generated by centmin.sh menu option 2 has the 2 includes files /usr/local/nginx/conf/503include-main.conf in server {} context outside any location context and /usr/local/nginx/conf/503include-only.conf within location context
    Code (Text):
      root /home/nginx/domains/testdomain.com/public;
      include /usr/local/nginx/conf/503include-main.conf;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    

    and in php.conf include file /usr/local/nginx/conf/503include-only.conf at /usr/local/nginx/conf/php.conf
    Code (Text):
    location ~ [^/]\.php(/|$) {
      include /usr/local/nginx/conf/503include-only.conf;


    centminmod-sitestatus-01.gif
     
    Last edited: Feb 7, 2017
    • Winner Winner x 1
  3. pamamolf

    pamamolf Well-Known Member

    2,821
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    7:18 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    When i use under location this one:

    Code:
    include /usr/local/nginx/conf/503include-only.conf;
    i am getting this:

    Code:
    nginx: [emerg] named location "@maintenance" can be on the server level only in /usr/local/nginx/conf/503include-main.conf:5
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    When i use:

    Code:
    include /usr/local/nginx/conf/503include-only.conf;
    under:

    Code:
    location ~ [^/]\.php(/|$) {
    then i am getting:

    Code:
    nginx: [emerg] unknown "maintenance" variable
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    Maybe i need to double check?
     
  4. eva2000

    eva2000 Administrator Staff Member

    30,956
    6,917
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,418
    Local Time:
    3:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    first check if include file /usr/local/nginx/conf/maintenance.conf is added to /usr/local/nginx/conf/nginx.conf.
    i.e. in /usr/local/nginx/conf/nginx.conf
    Code (Text):
    # uncomment cloudflare.conf include if using cloudflare for
    # server and/or vhost site
    #include /usr/local/nginx/conf/cloudflare.conf;
    include /usr/local/nginx/conf/maintenance.conf;
    include /usr/local/nginx/conf/vts_http.conf;
    include /usr/local/nginx/conf/geoip.conf;
    #include /usr/local/nginx/conf/pagespeedadmin.conf;
     
  5. pamamolf

    pamamolf Well-Known Member

    2,821
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    7:18 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    All good now :)

    Testing with ip's .....

    Thank you
     
  6. pamamolf

    pamamolf Well-Known Member

    2,821
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    7:18 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    All working great thanks !!
     
    Last edited: Feb 7, 2017
  7. eva2000

    eva2000 Administrator Staff Member

    30,956
    6,917
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,418
    Local Time:
    3:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    it's in each nginx vhost's public web root ;)
     
    • Like Like x 1