Want more timely Centmin Mod News Updates?
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 Premium Member Premium Member

    3,947
    400
    83
    May 31, 2014
    Ratings:
    +779
    Local Time:
    5:37 PM
    Nginx-1.17.x
    MariaDB 10.3.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

    47,294
    10,705
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,631
    Local Time:
    12:37 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    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
  3. pamamolf

    pamamolf Premium Member Premium Member

    3,947
    400
    83
    May 31, 2014
    Ratings:
    +779
    Local Time:
    5:37 PM
    Nginx-1.17.x
    MariaDB 10.3.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

    47,294
    10,705
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,631
    Local Time:
    12:37 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    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 Premium Member Premium Member

    3,947
    400
    83
    May 31, 2014
    Ratings:
    +779
    Local Time:
    5:37 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    All good now :)

    Testing with ip's .....

    Thank you
     
  6. pamamolf

    pamamolf Premium Member Premium Member

    3,947
    400
    83
    May 31, 2014
    Ratings:
    +779
    Local Time:
    5:37 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    All working great thanks !!
     
    Last edited: Feb 7, 2017
  7. eva2000

    eva2000 Administrator Staff Member

    47,294
    10,705
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,631
    Local Time:
    12:37 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    it's in each nginx vhost's public web root ;)
     
  8. ElChorizo

    ElChorizo Premium Member Premium Member

    15
    1
    3
    Apr 29, 2021
    Ratings:
    +2
    Local Time:
    9:37 AM
    1.19.10
    10.3.28
    Read all the threads about enabling maintenance mode on a per domain basis but never really saw a good answer. Can someone please post a quick walk through. I don't want to put every domain into maintenance mode if I'm upgrading only one site on the server.