Modern PHP Enterprise Systems Applications require high efficient fast loading web sites. These are the key concepts you must configure in your Nginx Web Server to have a high performance web application:
- Enable caching: Nginx has a built-in caching mechanism that can significantly improve website performance. You can enable caching by adding the following lines to your Nginx configuration file:
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m inactive=60m;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_valid 200 60m;
proxy_cache_valid 404 1m;
- Use gzip compression: Nginx can compress responses before sending them to the client, which can greatly reduce the amount of data that needs to be transferred. You can enable gzip compression by adding the following lines to your configuration file:
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
- Enable SSL: If you're not already using SSL, consider enabling it for improved security and search engine ranking along with parallel resource loading through HTTP2. You can enable SSL by adding the following lines to your configuration file:
listen 443 ssl;
ssl_certificate /path/to/certificate.crt;
ssl_certificate_key /path/to/private.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
- Use FastCGI caching: If you're using PHP-FPM, you can enable FastCGI caching to cache the output of PHP scripts. This can greatly improve website performance. You can enable FastCGI caching by adding the following lines to your configuration file:
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_valid 200 60m;
fastcgi_cache_valid 404 1m;
- Optimize static file serving: Nginx can serve static files very efficiently, but you can further optimize this by adding the following lines to your configuration file:
Optimize static file serving: Nginx can serve static files very efficiently, but you can further optimize this by adding the following lines to your configuration file:
Refer to the sample config files here:
Nginx with PHP-FPM in Vagrant Centos 7 Virtual Machine
Install PHP7 with FPM in a Vagrant Centos 7
Configure PHP in Virtual Machine to work as LEMP Server
Configure Nginx Web Server with SSL in a Vagrant Virtual Machine