Category Archives: Nginx

Use Nginx Helper without ngx_cache_purge module

Create a file in your website root folder named purge.php: <?php   // Allow only safe IP addresses //if ( $_SERVER[‘REMOTE_ADDR’] != "SERVER.IP.ADDRESS.HERE" ) die( "IP address not allowed!" );   echo date("Y-m-d H:i:s", time())." :: Checking cache file…<br />";   $cache_path = ‘/var/www/nginx-cache/’;   if ( !is_dir($cache_path) ) die( date("Y-m-d H:i:s", time())." :: ".htmlspecialchars($cache_path)." […]

Nginx PHP file upload size limit

Lets suppose you need to support uploading of 50MB files. Edit /etc/php5/fpm/php.ini file and set these parameters: upload_max_filesize = 50M post_max_size = 50Mupload_max_filesize = 50M post_max_size = 50M Edit /etc/nginx/nginx.conf and set this parameter: http { … client_max_body_size 50m; … }http { … client_max_body_size 50m; … } Restart PHP and Nginx services: service php5-fpm reload […]

Deny access to sensitive files with Nginx

Add this in the vhost file: # Protect specific TXT and config files location ~ /(\.|wp-config.php|readme.html|license.txt|schema.txt|password.txt|passwords.txt) { deny all; }   # Protect ~ files location ~ ~$ { access_log off; log_not_found off; deny all; }   # Protect .git files location ~ /\.git { access_log off; log_not_found off; deny all; }   # Protect […]

1 Billion hits/day with Nginx + PHP5-FPM + MySQL

Recently I tested Nginx + PHP-FPM + MySQL with Blitz.io service: 10,000 concurrent connections with Nginx + PHP-FPM + MySQL I have tested it again, but this time with 20,000 concurrent connections: As you can see from the above image, the rush generated 654,550 successful hits in 60 seconds and the average hit rate of […]

500 Million hits/day with Nginx + PHP-FPM + MySQL

I have recently registered to blitz.io, a very interested cloud service which allows users to stress-test a web server simulating up to 50K concurrent connections, with the possibility to specify different regions to originate requests, the HTTP method, the timeout and much more. This service can help to properly configure the web server (Nginx, Lighttpd, […]

Fix the Nginx 504 gateway timeout

If you run a Nginx web server you may have already encountered the annoying 504 Gateway Time-out errors. This kind of error messages are generated most probably by the PHP max execution time limit or by the FastCGI read timeout settings. Try raising max_execution_time parameter in /etc/php5/fpm/php.ini file: max_execution_time = 600max_execution_time = 600 Then you […]

Connect() to unix:/var/run/php5-fpm.sock failed

This is an example error message found on error.log file: 2014/02/17 01:46:47 [crit] 35655#0: *12739 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XX, server: www.website.com, request: "GET /index HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.website.com", referrer: "http://www.website.com/index"2014/02/17 01:46:47 [crit] 35655#0: *12739 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file […]

Configure FastCGI_Cache for WordPress and Nginx

Edit the vHost file of your WordPress blog as follow: # Define cache path, size, memory name, inactive time fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_use_stale updating error timeout invalid_header http_500; fastcgi_temp_path /var/cache/nginx/tmp;   # Add a custom header that shows if the page is cached or not # X-Cache: HIT = cached | […]

Enable Nginx status page

Make sure you have the module HttpStubStatusModule enabled: nginx -V | grep –color -o http_stub_statusnginx -V | grep –color -o http_stub_status Then add this text inside the server{} section: location /nginx_status { # Enable the Nginx status module stub_status on; # Disable server logging for this location access_log off; # IP address is allowed to […]

Configure PHP-CGI without Spawn-FCGI

Create a file /etc/init.d/php-cgi-starter with this content: #! /bin/sh ### BEGIN INIT INFO # Provides: PHP-CGI Starter # Required-Start: # Required-Stop: # Should-Start: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: script used to start PHP-CGI # Description: ### END INIT INFO   #PATH=/sbin:/bin   . /lib/lsb/init-functions   BIND=127.0.0.1:9000 USER=www-data […]