Last active
August 29, 2015 14:05
-
-
Save vovanbo/d5fa04ca4b7bef5253a5 to your computer and use it in GitHub Desktop.
Nginx config with maintenance support (PHP, CodeIgniter, Nginx)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name example.com; | |
charset utf-8; | |
rewrite_log on; | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log notice; | |
client_max_body_size 20M; | |
root /usr/share/nginx/www/example.com/public; | |
index index.html index.php; | |
# Maintenance mode | |
# ---------------- | |
# Create a file public/site_down to trigger a 503 response with a static | |
# maintenance page. User's from the local network will still be able to | |
# get through though. | |
set $maintenance 0; | |
if (-f $document_root/site_down) { | |
set $maintenance 1; | |
} | |
if ($remote_addr ~ "^(XXX.XXX.XXX.XXX)$") { | |
set $maintenance 0; | |
} | |
if ($maintenance = 1) { | |
return 503; | |
} | |
location / { | |
try_files $uri $uri/ /index.php?$uri; | |
} | |
error_page 503 @maintenance_page; | |
location @maintenance_page { | |
rewrite ^(.*)$ /maintenance.html break; | |
} | |
location ~ \.php$ { | |
include fastcgi_params; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_split_path_info ^(.+\.php)(.*)$; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
location ~* \.(jpg|jpeg|png|gif|css|js|ico|svg)(\?[0-9]+)?$ { | |
expires max; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment