SlideShare a Scribd company logo
Nginx
  +
 PHP
2012-09-15 @wokamoto
デジタルキューブ で WordPress とか、
サイトのパフォーマンスチューニングとか
やってます。
 twitter : @wokamoto
 facebook : wokamoto
 http://profiles.wordpress.org/wokamoto
 https://github.com/wokamoto
http://nginx.org/ja/
WordPress
高速化&スマート運用
必携ガイド
Nginx ?
http://nginx.com/ , http://nginx.org/
W3Techs の調査では


上位 1,000,000 サイトの
 12.5%、
上位 100,000 サイトの
 19.4%

で採用されている

         http://w3techs.com/technologies/
             cross/web_server/ranking
How to use
   Nginx
 with PHP?
Apache の mod_php のように
Nginx に直接組み込むことは
        できない


 →fast CGI ( php-fpm ) で
【 nginx.conf の例 】
server {
  listen   80 default;
  server_name _;
  root      /path/to/app;
  index     index.php index.html index.htm;
  charset    utf-8;

    location ~ .php$ {
      fastcgi_pass unix:/var/run/php-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME
                     $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }
}
【 php-fpm.conf の例 】
[www]
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0666

user = nginx
group = nginx

pm = dynamic
pm.max_children = 15
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 7
Nginx's
performance
Apache, mod_php, WordPress
$ ab -n 100 -c 10
      AWS t1.micro
  Apache, php with APC
(WordPress トップページ)
 Requests per second:   4.26 [#/sec] (mean)

 Time per request:      2346.174 [ms] (mean)

 Connection Times Total: 2309 [ms] (mean)
Nginx, php-fpm, WordPress




          1617
           1617
$ ab -n 100 -c 10
     AWS t1.micro
  Nginx, php with APC
(WordPress トップページ)
 Requests per second:   5.79 [#/sec] (mean)

 Time per request:      1726.535 [ms] (mean)

 Connection Times Total: 1617 [ms] (mean)
Reverse
proxy Cache
$ ab -n 1000 -c 100
     AWS t1.micro
  Nginx, php with APC
(WordPress トップページ)
 Requests per second:   141.24 [#/sec] (mean)

 Time per request:      708.007 [ms] (mean)

 Connection Times Total: 636 [ms] (mean)
【 nginx.conf の例 】
http {
     :
  proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2
                keys_zone=czone:32m max_size=256m inactive=1440m;
  proxy_temp_path /var/cache/nginx/proxy_temp;
  proxy_cache_key "$scheme:/   /$host$request_uri";
  proxy_set_header Host              $host;
  proxy_set_header Remote-Addr         $remote_addr;
  proxy_set_header X-Forwarded-Host $host;
  proxy_set_header X-Forwarded-Server $host;
  proxy_set_header X-Forwarded-For      $proxy_add_x_forwarded_for;
  proxy_set_header Accept-Encoding     "";
  proxy_connect_timeout 5;
  proxy_send_timeout 10;
  proxy_read_timeout 120;
  proxy_cache_lock on;
  proxy_cache_lock_timeout 5s;

    upstream backend {
      server unix:/var/run/nginx-backend.sock;
    }
        :
}
server {
  listen   80 default;
  server_name _;
  root      /path/to/app;
  index     index.php index.html index.htm;

    location ~* .(js|css|html?|xml|jpe?g|gif|png|swf|wmv|flv|ico)$ {
      expires 365d;
    }

    location / {
      set $do_not_cache 0;
      if ($request_method = POST) {
        set $do_not_cache 1;
      }
      proxy_no_cache     $do_not_cache;
      proxy_cache_bypass $do_not_cache;
      proxy_redirect    off;
      proxy_cache       czone;
      proxy_cache_key     "$scheme://$host$request_uri$is_args$args$mobile";
      proxy_cache_valid 200 0m;
      proxy_pass http://backend;
    }
}
server {
  listen   unix:/var/run/nginx-backend.sock;
  server_name _;
  root      /path/to/app;
  index     index.php index.html index.htm;
  charset    utf-8;

    gzip          off;
    gzip_vary      off;

    location ~ .php$ {
      fastcgi_pass unix:/var/run/php-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME
                     $document_root$fastcgi_script_name;
      include        fastcgi_params;
      fastcgi_pass_header "X-Accel-Redirect";
      fastcgi_pass_header "X-Accel-Buffering";
      fastcgi_pass_header "X-Accel-Charset";
      fastcgi_pass_header "X-Accel-Expires";
      fastcgi_pass_header "X-Accel-Limit-Rate";
    }
}
Reverse Proxy にキャッシュ
    させる時間を PHP で制御
<?php
header('X-Accel-Expires: '. 60 * 60 * 24);
?>
Easy to Use
http://ja.megumi-cloud.com/
Twitter : @wokamoto

More Related Content

What's hot

Ajax basics
Ajax basicsAjax basics
Varnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyVarnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyPeter Keung
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with phpElizabeth Smith
 
To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)
Geoffrey Anderson
 
LogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeLogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesome
James Turnbull
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
박 민규
 
HTTP For the Good or the Bad
HTTP For the Good or the BadHTTP For the Good or the Bad
HTTP For the Good or the Bad
Xavier Mertens
 
From zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and ElasticsearchFrom zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and Elasticsearch
Rafał Kuć
 
Elastic stack
Elastic stackElastic stack
Elastic stack
Minsoo Jun
 
Tecnologias Open Source para Alta Disponibilidade e Segurança de Aplicações Web
Tecnologias Open Source para  Alta Disponibilidade e Segurança de Aplicações WebTecnologias Open Source para  Alta Disponibilidade e Segurança de Aplicações Web
Tecnologias Open Source para Alta Disponibilidade e Segurança de Aplicações Web
Alexandro Silva
 
Engage 2013 - Multi Channel Data Collection
Engage 2013 - Multi Channel Data CollectionEngage 2013 - Multi Channel Data Collection
Engage 2013 - Multi Channel Data CollectionWebtrends
 
Tools used for debugging
Tools used for debuggingTools used for debugging
Tools used for debugging
Marian Marinov
 
Eduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereEduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereStarTech Conference
 
Puppet
PuppetPuppet
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
Brandon Lamb
 
Realtime Communication Techniques with PHP
Realtime Communication Techniques with PHPRealtime Communication Techniques with PHP
Realtime Communication Techniques with PHPWaterSpout
 
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and VarnishMagento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Yireo
 

What's hot (20)

Ajax basics
Ajax basicsAjax basics
Ajax basics
 
Varnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyVarnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites fly
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
 
To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)
 
LogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeLogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesome
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
 
HTTP For the Good or the Bad
HTTP For the Good or the BadHTTP For the Good or the Bad
HTTP For the Good or the Bad
 
From zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and ElasticsearchFrom zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and Elasticsearch
 
Elastic stack
Elastic stackElastic stack
Elastic stack
 
Tecnologias Open Source para Alta Disponibilidade e Segurança de Aplicações Web
Tecnologias Open Source para  Alta Disponibilidade e Segurança de Aplicações WebTecnologias Open Source para  Alta Disponibilidade e Segurança de Aplicações Web
Tecnologias Open Source para Alta Disponibilidade e Segurança de Aplicações Web
 
Engage 2013 - Multi Channel Data Collection
Engage 2013 - Multi Channel Data CollectionEngage 2013 - Multi Channel Data Collection
Engage 2013 - Multi Channel Data Collection
 
Tools used for debugging
Tools used for debuggingTools used for debugging
Tools used for debugging
 
ReplacingSquidWithATS
ReplacingSquidWithATSReplacingSquidWithATS
ReplacingSquidWithATS
 
Eduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereEduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhere
 
Puppet
PuppetPuppet
Puppet
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
 
Realtime Communication Techniques with PHP
Realtime Communication Techniques with PHPRealtime Communication Techniques with PHP
Realtime Communication Techniques with PHP
 
Ruby Postgres
Ruby PostgresRuby Postgres
Ruby Postgres
 
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and VarnishMagento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
 
Scaling WordPress
Scaling WordPressScaling WordPress
Scaling WordPress
 

Viewers also liked

PHP를 위한 NginX(엔진엑스) 시작과 설정
PHP를 위한 NginX(엔진엑스) 시작과 설정PHP를 위한 NginX(엔진엑스) 시작과 설정
PHP를 위한 NginX(엔진엑스) 시작과 설정
Jin wook
 
From LAMP to LNNP
From LAMP to LNNPFrom LAMP to LNNP
From LAMP to LNNP
Giorgio Cefaro
 
mod_php vs. FastCGI 原理与比较
mod_php vs. FastCGI 原理与比较mod_php vs. FastCGI 原理与比较
mod_php vs. FastCGI 原理与比较
Ji ZHANG
 
Running php on nginx
Running php on nginxRunning php on nginx
Running php on nginx
Harald Zeitlhofer
 
Word press on conoha このべん #3
Word press on conoha このべん #3Word press on conoha このべん #3
Word press on conoha このべん #3
Wataru OKAMOTO
 
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OSSupercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
CloudLinux
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructure
mkherlakian
 
Techtalk2015 MOD_PHP vs PHP-FPM
Techtalk2015 MOD_PHP vs PHP-FPMTechtalk2015 MOD_PHP vs PHP-FPM
Techtalk2015 MOD_PHP vs PHP-FPM
Webscale
 
PHP7実環境ベンチ2016春
PHP7実環境ベンチ2016春PHP7実環境ベンチ2016春
PHP7実環境ベンチ2016春
Ryo Tomidokoro
 
PHP Files: An Introduction
PHP Files: An IntroductionPHP Files: An Introduction
PHP Files: An Introduction
Jacques Woodcock
 
第2回勉強会資料 柏木
第2回勉強会資料 柏木第2回勉強会資料 柏木
第2回勉強会資料 柏木
beyond0iwamoto
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLI
Jacques Woodcock
 
PHP-FPMとuWSGI——mod_php以外の選択肢を探る
PHP-FPMとuWSGI——mod_php以外の選択肢を探るPHP-FPMとuWSGI——mod_php以外の選択肢を探る
PHP-FPMとuWSGI——mod_php以外の選択肢を探るYoshio Hanawa
 
Ultrafast WordPress Virtual Word camp2015
Ultrafast WordPress Virtual  Word camp2015 Ultrafast WordPress Virtual  Word camp2015
Ultrafast WordPress Virtual Word camp2015
Yuta Sakamoto
 
realpathキャッシュと OPcacheの面倒すぎる関係
realpathキャッシュと OPcacheの面倒すぎる関係realpathキャッシュと OPcacheの面倒すぎる関係
realpathキャッシュと OPcacheの面倒すぎる関係
Yoshio Hanawa
 
PHP development with Docker
PHP development with DockerPHP development with Docker
PHP development with Docker
Yosh de Vos
 
Alternative Infrastucture
Alternative InfrastuctureAlternative Infrastucture
Alternative Infrastucture
Marc Seeger
 
How to deploy PHP projects with docker
How to deploy PHP projects with dockerHow to deploy PHP projects with docker
How to deploy PHP projects with docker
Ruoshi Ling
 
How Flipkart scales PHP
How Flipkart scales PHPHow Flipkart scales PHP
How Flipkart scales PHP
Siddhartha Reddy Kothakapu
 

Viewers also liked (20)

PHP를 위한 NginX(엔진엑스) 시작과 설정
PHP를 위한 NginX(엔진엑스) 시작과 설정PHP를 위한 NginX(엔진엑스) 시작과 설정
PHP를 위한 NginX(엔진엑스) 시작과 설정
 
From LAMP to LNNP
From LAMP to LNNPFrom LAMP to LNNP
From LAMP to LNNP
 
mod_php vs. FastCGI 原理与比较
mod_php vs. FastCGI 原理与比较mod_php vs. FastCGI 原理与比较
mod_php vs. FastCGI 原理与比较
 
Running php on nginx
Running php on nginxRunning php on nginx
Running php on nginx
 
Word press on conoha このべん #3
Word press on conoha このべん #3Word press on conoha このべん #3
Word press on conoha このべん #3
 
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OSSupercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructure
 
Techtalk2015 MOD_PHP vs PHP-FPM
Techtalk2015 MOD_PHP vs PHP-FPMTechtalk2015 MOD_PHP vs PHP-FPM
Techtalk2015 MOD_PHP vs PHP-FPM
 
PHP7実環境ベンチ2016春
PHP7実環境ベンチ2016春PHP7実環境ベンチ2016春
PHP7実環境ベンチ2016春
 
PHP Files: An Introduction
PHP Files: An IntroductionPHP Files: An Introduction
PHP Files: An Introduction
 
第2回勉強会資料 柏木
第2回勉強会資料 柏木第2回勉強会資料 柏木
第2回勉強会資料 柏木
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLI
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
PHP-FPMとuWSGI——mod_php以外の選択肢を探る
PHP-FPMとuWSGI——mod_php以外の選択肢を探るPHP-FPMとuWSGI——mod_php以外の選択肢を探る
PHP-FPMとuWSGI——mod_php以外の選択肢を探る
 
Ultrafast WordPress Virtual Word camp2015
Ultrafast WordPress Virtual  Word camp2015 Ultrafast WordPress Virtual  Word camp2015
Ultrafast WordPress Virtual Word camp2015
 
realpathキャッシュと OPcacheの面倒すぎる関係
realpathキャッシュと OPcacheの面倒すぎる関係realpathキャッシュと OPcacheの面倒すぎる関係
realpathキャッシュと OPcacheの面倒すぎる関係
 
PHP development with Docker
PHP development with DockerPHP development with Docker
PHP development with Docker
 
Alternative Infrastucture
Alternative InfrastuctureAlternative Infrastucture
Alternative Infrastucture
 
How to deploy PHP projects with docker
How to deploy PHP projects with dockerHow to deploy PHP projects with docker
How to deploy PHP projects with docker
 
How Flipkart scales PHP
How Flipkart scales PHPHow Flipkart scales PHP
How Flipkart scales PHP
 

Similar to Nginx + PHP

Running PHP on nginx
Running PHP on nginxRunning PHP on nginx
Running PHP on nginx
Harald Zeitlhofer
 
Running PHP on Nginx
Running PHP on NginxRunning PHP on Nginx
Running PHP on Nginx
Harald Zeitlhofer
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
Kevin Jones
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
NGINX, Inc.
 
WordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngineWordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngine
NGINX, Inc.
 
PHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on NginxPHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on Nginx
Harald Zeitlhofer
 
10 Million hits a day with WordPress using a $15 VPS
10 Million hits a day  with WordPress using a $15 VPS10 Million hits a day  with WordPress using a $15 VPS
10 Million hits a day with WordPress using a $15 VPS
Paolo Tonin
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
Jeff Jones
 
Nginx internals
Nginx internalsNginx internals
Nginx internalsliqiang xu
 
ApacheConNA 2015: What's new in Apache httpd 2.4
ApacheConNA 2015: What's new in Apache httpd 2.4ApacheConNA 2015: What's new in Apache httpd 2.4
ApacheConNA 2015: What's new in Apache httpd 2.4
Jim Jagielski
 
How to install nginx vs unicorn
How to install nginx vs unicornHow to install nginx vs unicorn
How to install nginx vs unicorn
baran19901990
 
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
LumoSpark
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin JonesITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
Ortus Solutions, Corp
 
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটিWordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
Faysal Shahi
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slides
mkherlakian
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
Seravo
 
Study2study#4 nginx conf_1_24
Study2study#4 nginx conf_1_24Study2study#4 nginx conf_1_24
Study2study#4 nginx conf_1_24Naoya Nakazawa
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统yiditushe
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 

Similar to Nginx + PHP (20)

Running PHP on nginx
Running PHP on nginxRunning PHP on nginx
Running PHP on nginx
 
Running PHP on Nginx
Running PHP on NginxRunning PHP on Nginx
Running PHP on Nginx
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
WordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngineWordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngine
 
PHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on NginxPHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on Nginx
 
10 Million hits a day with WordPress using a $15 VPS
10 Million hits a day  with WordPress using a $15 VPS10 Million hits a day  with WordPress using a $15 VPS
10 Million hits a day with WordPress using a $15 VPS
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
Nginx internals
Nginx internalsNginx internals
Nginx internals
 
ApacheConNA 2015: What's new in Apache httpd 2.4
ApacheConNA 2015: What's new in Apache httpd 2.4ApacheConNA 2015: What's new in Apache httpd 2.4
ApacheConNA 2015: What's new in Apache httpd 2.4
 
Oscon 2011 - ATS
Oscon 2011 - ATSOscon 2011 - ATS
Oscon 2011 - ATS
 
How to install nginx vs unicorn
How to install nginx vs unicornHow to install nginx vs unicorn
How to install nginx vs unicorn
 
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin JonesITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
 
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটিWordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slides
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
Study2study#4 nginx conf_1_24
Study2study#4 nginx conf_1_24Study2study#4 nginx conf_1_24
Study2study#4 nginx conf_1_24
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 

More from Wataru OKAMOTO

re:Invent 2015 参加報告
re:Invent 2015 参加報告re:Invent 2015 参加報告
re:Invent 2015 参加報告
Wataru OKAMOTO
 
wp cli
wp cliwp cli
WordPress Cloud Design Pattern
WordPress  Cloud Design PatternWordPress  Cloud Design Pattern
WordPress Cloud Design Pattern
Wataru OKAMOTO
 
High performance web server
High performance web serverHigh performance web server
High performance web server
Wataru OKAMOTO
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
Wataru OKAMOTO
 
WordPress を使いこなそう
WordPress を使いこなそうWordPress を使いこなそう
WordPress を使いこなそうWataru OKAMOTO
 

More from Wataru OKAMOTO (10)

re:Invent 2015 参加報告
re:Invent 2015 参加報告re:Invent 2015 参加報告
re:Invent 2015 参加報告
 
Amimoto auto scaling
Amimoto auto scalingAmimoto auto scaling
Amimoto auto scaling
 
wp cli
wp cliwp cli
wp cli
 
Wckansai 2014
Wckansai 2014Wckansai 2014
Wckansai 2014
 
Sacss sp5
Sacss sp5Sacss sp5
Sacss sp5
 
StaticPress
StaticPressStaticPress
StaticPress
 
WordPress Cloud Design Pattern
WordPress  Cloud Design PatternWordPress  Cloud Design Pattern
WordPress Cloud Design Pattern
 
High performance web server
High performance web serverHigh performance web server
High performance web server
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
 
WordPress を使いこなそう
WordPress を使いこなそうWordPress を使いこなそう
WordPress を使いこなそう
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

Nginx + PHP

  • 1. Nginx + PHP 2012-09-15 @wokamoto
  • 2. デジタルキューブ で WordPress とか、 サイトのパフォーマンスチューニングとか やってます。 twitter : @wokamoto facebook : wokamoto http://profiles.wordpress.org/wokamoto https://github.com/wokamoto
  • 5.
  • 8. W3Techs の調査では 上位 1,000,000 サイトの 12.5%、 上位 100,000 サイトの 19.4% で採用されている http://w3techs.com/technologies/ cross/web_server/ranking
  • 9.
  • 10. How to use Nginx with PHP?
  • 11. Apache の mod_php のように Nginx に直接組み込むことは できない →fast CGI ( php-fpm ) で
  • 12. 【 nginx.conf の例 】 server { listen 80 default; server_name _; root /path/to/app; index index.php index.html index.htm; charset utf-8; location ~ .php$ { fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
  • 13. 【 php-fpm.conf の例 】 [www] listen = /var/run/php-fpm.sock listen.owner = nginx listen.group = nginx listen.mode = 0666 user = nginx group = nginx pm = dynamic pm.max_children = 15 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 7
  • 16. $ ab -n 100 -c 10 AWS t1.micro Apache, php with APC (WordPress トップページ) Requests per second: 4.26 [#/sec] (mean) Time per request: 2346.174 [ms] (mean) Connection Times Total: 2309 [ms] (mean)
  • 18. $ ab -n 100 -c 10 AWS t1.micro Nginx, php with APC (WordPress トップページ) Requests per second: 5.79 [#/sec] (mean) Time per request: 1726.535 [ms] (mean) Connection Times Total: 1617 [ms] (mean)
  • 20. $ ab -n 1000 -c 100 AWS t1.micro Nginx, php with APC (WordPress トップページ) Requests per second: 141.24 [#/sec] (mean) Time per request: 708.007 [ms] (mean) Connection Times Total: 636 [ms] (mean)
  • 21. 【 nginx.conf の例 】 http { : proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=czone:32m max_size=256m inactive=1440m; proxy_temp_path /var/cache/nginx/proxy_temp; proxy_cache_key "$scheme:/ /$host$request_uri"; proxy_set_header Host $host; proxy_set_header Remote-Addr $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Accept-Encoding ""; proxy_connect_timeout 5; proxy_send_timeout 10; proxy_read_timeout 120; proxy_cache_lock on; proxy_cache_lock_timeout 5s; upstream backend { server unix:/var/run/nginx-backend.sock; } : }
  • 22. server { listen 80 default; server_name _; root /path/to/app; index index.php index.html index.htm; location ~* .(js|css|html?|xml|jpe?g|gif|png|swf|wmv|flv|ico)$ { expires 365d; } location / { set $do_not_cache 0; if ($request_method = POST) { set $do_not_cache 1; } proxy_no_cache $do_not_cache; proxy_cache_bypass $do_not_cache; proxy_redirect off; proxy_cache czone; proxy_cache_key "$scheme://$host$request_uri$is_args$args$mobile"; proxy_cache_valid 200 0m; proxy_pass http://backend; } }
  • 23. server { listen unix:/var/run/nginx-backend.sock; server_name _; root /path/to/app; index index.php index.html index.htm; charset utf-8; gzip off; gzip_vary off; location ~ .php$ { fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass_header "X-Accel-Redirect"; fastcgi_pass_header "X-Accel-Buffering"; fastcgi_pass_header "X-Accel-Charset"; fastcgi_pass_header "X-Accel-Expires"; fastcgi_pass_header "X-Accel-Limit-Rate"; } }
  • 24. Reverse Proxy にキャッシュ させる時間を PHP で制御 <?php header('X-Accel-Expires: '. 60 * 60 * 24); ?>