Skip to content

Instantly share code, notes, and snippets.

@clasense4
Created December 3, 2014 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clasense4/46cd276f0828d09bd46f to your computer and use it in GitHub Desktop.
Save clasense4/46cd276f0828d09bd46f to your computer and use it in GitHub Desktop.
Simple Nginx maintenance script

Simple Nginx Maintenance Script

Well, I'm too lazy to doing some command just for change the configuration, here is the script. The logic is simple, change app port from 80 into 8313, and make the port 80 maintenance. And to revert it, change app port from 8313 into 80, and make the maintenance.conf disable by change it into extension .confs.

To use it, make sure the filename just look like below, and then chmod a+x *.sh. Then ./maintenance.sh to make it maintenance mode or ./demaintenance.sh to revert.

maintenance.sh

#!/bin/bash
# @name     : Maintenance script for CRM App
#             Change the Application port from 80, into 8313
#             and make port 80 go maintenance
# @author   : clasense4@gmail.com
# @date     : 3-12-2014

cd /etc/nginx/conf.d/
mv vhost_crm.conf vhost_crm.confs
mv vhost_crm_maintenance.confs vhost_crm_maintenance.conf
echo "Application Port is at 8313"
mv vhost_maintenance.confs vhost_maintenance.conf
echo "Port 80 is now at maintenance"
service nginx reload
echo "service nginx reload"

demaintenance.sh

#!/bin/bash
# @name    	: DeMaintenance script for CRM App
# 			  Change the Application port from 8313, into 80
# 			  and make maintenance script disable
# @author	: clasense4@gmail.com
# @date 	: 3-12-2014

cd /etc/nginx/conf.d/
mv vhost_crm.confs vhost_crm.conf
mv vhost_crm_maintenance.conf vhost_crm_maintenance.confs
echo "Application Port is at 80"
mv vhost_maintenance.conf vhost_maintenance.confs
echo "Port 80 is now disable"
service nginx reload
echo "service nginx reload"

vhost_app.conf

server {
    listen 80;
    root /var/www/p2tk-crm/public;
    index index.php;
    server_tokens off;

    access_log /etc/nginx/conf.d/logs/p2tk-crm_access_log;
    error_log /etc/nginx/conf.d/logs/p2tk-crm_error_log error;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
        server_tokens off;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
       expires 365d;
    }
}

vhost_app_maintenance.confs

server {
    listen 8313;
    root /var/www/p2tk-crm/public;
    index index.php;
    server_tokens off;

    access_log /etc/nginx/conf.d/logs/p2tk-crm_access_log;
    error_log /etc/nginx/conf.d/logs/p2tk-crm_error_log error;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
        server_tokens off;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
       expires 365d;
    }
}

vhost_maintenance.confs

server {
    listen 80;
    root /var/www/maintenance;
    index index.php;
    server_tokens off;

    access_log /etc/nginx/conf.d/logs/p2tk-crm_access_log;
    error_log /etc/nginx/conf.d/logs/p2tk-crm_error_log error;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
        server_tokens off;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
       expires 365d;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment