I'm benchmarking these two setups (installed on the same system)
nginx 1.8.0 + php-fpm (5.6.14-0+deb8u1)
apache 2.4.10 + mod_php (5.6.14-0+deb8u1)
Have runned through the output of phpinfo()
and they look the same (haven't changed anything manually)
Hardware:
Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz + 16GB RAM
Test 1 - one single HTTP (PHP) request once (no concurrency)
nginx ~= 360ms
apache ~= 320ms
Test 2 - loading the website with all static content css/js etc
nginx ~= 7.7sec
apache ~= 8.9sec
What is it that I have missed in the configuration?
AllowOverride All
is even set on apache and apache still outperform nginx on a PHP request!?
nginx
user www-data;
worker_processes 8;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
autoindex off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
index index.php index.html index.htm;
gzip on;
server {
listen 80;
server_name domain.com;
root /var/www/public/secure;
access_log /var/log/nginx/access.log;
# Add trailing slash
rewrite ^([^.\?]*[^/])$ $1/ permanent;
location / {
try_files $uri $uri/ @missing;
}
location @missing {
rewrite ^ /index.php;
}
location ~ .php$ {
include /var/ini/nginx/fastcgi.conf;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME /var/www/public/secure/index.php;
}
}
}
apache
Listen 8080
<Directory /var/www>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
NameVirtualHost *:8080
<VirtualHost *:8080>
ServerName domain.com
DocumentRoot /var/www/public/secure
#LogLevel debug
ErrorLog /var/www_log/error.log
CustomLog /var/www_log/access.log common
</VirtualHost>