SlideShare a Scribd company logo
Maximizing Drupal 8
Performance with
NGINX
Wednesday, 20 January 2016
MORE INFORMATION AT
NGINX.COM
Your Questions
1. Who are we?
● Floyd Smith, Technical Marketing Writer. Author of NGINX blog post, “8 Tips for Drupal 8
Performance”.
● Faisal Memon, Product Marketer
2. What’s new in Drupal 8?
3. How can I implement a high-performance site?
4. How do NGINX and NGINX Plus fit into my efforts?
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in Drupal 8
● Planning Site Architecture
● Replacing Your Web Server
● Drupal Specifics
- Drupal 8 Configuration
● Caching
- Why cache with NGINX?
- Microcaching
- Cache Purging with NGINX Plus
● Reverse Proxy Server
- Load Balancing
- Session Persistence
- Bonus: SSL/TLS and HTTP/2
● Questions?
MORE INFORMATION AT
NGINX.COM
What’s New in Drupal 8
1. Mobile improvements. Full support for mobile site templates and easy backend
administration from a mobile device.
2. Data and presentation layer uncoupling. The Drupal API is now fully RESTful, making it
easier to use with Angular.js, Ember.js, and other client-side content extraction and display
tools.
3. Support for Symfony2. Symfony 2 is an up-to-date, object-oriented PHP framework, well
known for customer relationship management (CRM) integration.
4. Twig support. Twig is a frontend library and template engine that eliminates some
disadvantages of pure PHP while embracing the latest PHP standards.
5. Security improvements. New features offer additional ways to make systems more secure.
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in Drupal 8
● Planning Site Architecture
● Replacing Your Web Server
● Drupal Specifics
- Drupal 8 Configuration
● Caching
- Why cache with NGINX?
- Microcaching
- Cache Purging with NGINX Plus
● Reverse Proxy Server
- Load Balancing
- Session Persistence
- Bonus: SSL/TLS and HTTP/2
● Questions?
MORE INFORMATION AT
NGINX.COM
Planning Your Site Architecture
1. Current architecture. Evaluate your current site traffic and performance.
2. Goals. Immediate problems, future growth
3. Estimate impact of changes. Open source NGINX or NGINX Plus as web server, reverse
proxy server, load balancer, more.
4. Plan for growth. Estimate likely and possible growth and speed of growth.
5. Factor in the cloud. Use cloud from scratch, expand into the cloud, move into the cloud.
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in Drupal 8
● Planning Site Architecture
● Replacing Your Web Server
● Drupal Specifics
- Drupal 8 Configuration
● Caching
- Why cache with NGINX?
- Microcaching
- Cache Purging with NGINX Plus
● Reverse Proxy Server
- Load Balancing
- Session Persistence
- Bonus: SSL/TLS and HTTP/2
● Questions?
MORE INFORMATION AT
NGINX.COM
Replacing Your Web Server
1. Replace Apache with NGINX or NGINX Plus. Immediate performance fix. Enables caching
for static and dynamic content. (More on this soon.) Does not enable multiple app servers.
2. More performance on same hardware. Event loop replaces thread-per-connection, solves
C10K problem.
3. Requires new server configuration. Replace
familiar Apache configuration with tighter, more
efficient (IMHO) NGINX configuration.
4. Independent of NGINX as reverse proxy
server. You can use NGINX as a reverse
proxy server with or without using NGINX as your web server; very flexible.
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in Drupal 8
● Planning Site Architecture
● Replacing Your Web Server
● Drupal Specifics
- Drupal 8 Configuration
● Caching
- Why cache with NGINX?
- Microcaching
- Cache Purging with NGINX Plus
● Reverse Proxy Server
- Load Balancing
- Session Persistence
- Bonus: SSL/TLS and HTTP/2
● Questions?
MORE INFORMATION AT
NGINX.COM
NGINX configuration for Drupal
• Minor changes to nginx.conf for Drupal 8
• Mostly related to update.php front controller
• Sample configuration available on NGINX wiki
• https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/
MORE INFORMATION AT
NGINX.COM
Change #1: Accommodating update.php front controller
location ~ '.php$ {
...
}
location ~ '.php$|^/update.php' {
...
}
• To accommodate URIs such as: /update.php/selection
• Without this change NGINX will return a 404 error
• Less strict (and more future proof) alternative:
• Will match (and break) legacy Drupal URIs such as /blog/index.php/legacy
location ~ '.php$(/|$) {
MORE INFORMATION AT
NGINX.COM
Change #2: Non-greedy match
fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_split_path_info ^(.+?.php)(|/.*)$;
• To accommodate URIs such as: /core/authorize.php/core/authorize.php
• Without this change NGINX will return a 404 error
• Greedy match (left side) means entire URI will be SCRIPT_FILENAME
• Non-greedy match (right side) means first authorize.php will be matched
MORE INFORMATION AT
NGINX.COM
Change #3: Default location
location / {
try_files $uri @rewrite;
}
location /{
try_files $uri /index.php?$query_string;
}
• Change was made for Drupal 7
• Older version can cause query string to be altered
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in Drupal 8
● Planning Site Architecture
● Replacing Your Web Server
● Drupal Specifics
- Drupal 8 Configuration
● Caching
- Why cache with NGINX?
- Microcaching
- Cache Purging with NGINX Plus
● Reverse Proxy Server
- Load Balancing
- Session Persistence
- Bonus: SSL/TLS and HTTP/2
● Conclusion
● Questions?
MORE INFORMATION AT
NGINX.COM
Why Cache with NGINX?
Source: http://bbc.in/1O8qHbi
MORE INFORMATION AT
NGINX.COM
Microcaching with NGINX
• Cache content for a short time, as little as 1 second
• Site content is out of date for max 1 second
• Significant performance gains even for that short of a time
MORE INFORMATION AT
NGINX.COM
Microcaching with NGINX
proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2
inactive=600s max_size=100m;
server {
proxy_cache cache;
proxy_cache_valid 200 1s;
...
}
• Cache 200 responses for 1 second
MORE INFORMATION AT
NGINX.COM
Optimized Microcaching with NGINX
server {
proxy_cache cache;
proxy_cache_valid 200 1s;
proxy_cache_lock on;
proxy_cache_use_stale updating;
...
}
• proxy_cache_lock – If multiple simultaneous requests for the same
uncached or stale content, only one request allowed through. Other is
queued.
• proxy_cache_use_stale – Serve stale content when while cached entry is
being updated
MORE INFORMATION AT
NGINX.COM
Cache Purging with NGINX Plus
proxy_cache_path /tmp/cache keys_zone=mycache:10m levels=1:2
inactive=60s;
map $request_method $purge_method {
PURGE 1;
default 0;
}
server {
proxy_cache mycache;
proxy_cache_purge $purge_method;
}
$ curl -X PURGE -D – "http://www.example.com/*"
HTTP/1.1 204 No Content
…
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in Drupal 8
● Planning Site Architecture
● Replacing Your Web Server
● Drupal Specifics
- Drupal 8 Configuration
● Caching
- Why cache with NGINX?
- Microcaching
- Cache Purging with NGINX Plus
● Reverse Proxy Server
- Load Balancing
- Session Persistence
- Bonus: SSL/TLS and HTTP/2
● Questions?
MORE INFORMATION AT
NGINX.COM
Load Balancing with NGINX
MORE INFORMATION AT
NGINX.COM
Session Persistence with NGINX Plus
• Stick client to the same server for duration of a session
• Multiple methods:
• NGINX tracks application session cookie: PHPSESSIONID
• NGINX inserts its own cookie
• Stick Route: Persistence based on cookie, HTTP header, etc.
• IP Hash (Available in Open Source)
• Session Draining: Gracefully remove servers from the load balancing pool
MORE INFORMATION AT
NGINX.COM
SSL offloading with NGINX
MORE INFORMATION AT
NGINX.COM
HTTP/2 with NGINX
NGINX translates HTTP/2 to the language your application speaks
MORE INFORMATION AT
NGINX.COM
Agenda
● What’s New in Drupal 8
● Planning Site Architecture
● Replacing Your Web Server
● Drupal Specifics
- Drupal 8 Configuration
● Caching
- Why cache with NGINX?
- Microcaching
- Cache Purging with NGINX Plus
● Reverse Proxy Server
- Load Balancing
- Session Persistence
- Bonus: SSL/TLS and HTTP/2
● Questions?

More Related Content

Drupal 8 and NGINX

  • 1. Maximizing Drupal 8 Performance with NGINX Wednesday, 20 January 2016
  • 2. MORE INFORMATION AT NGINX.COM Your Questions 1. Who are we? ● Floyd Smith, Technical Marketing Writer. Author of NGINX blog post, “8 Tips for Drupal 8 Performance”. ● Faisal Memon, Product Marketer 2. What’s new in Drupal 8? 3. How can I implement a high-performance site? 4. How do NGINX and NGINX Plus fit into my efforts?
  • 3. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in Drupal 8 ● Planning Site Architecture ● Replacing Your Web Server ● Drupal Specifics - Drupal 8 Configuration ● Caching - Why cache with NGINX? - Microcaching - Cache Purging with NGINX Plus ● Reverse Proxy Server - Load Balancing - Session Persistence - Bonus: SSL/TLS and HTTP/2 ● Questions?
  • 4. MORE INFORMATION AT NGINX.COM What’s New in Drupal 8 1. Mobile improvements. Full support for mobile site templates and easy backend administration from a mobile device. 2. Data and presentation layer uncoupling. The Drupal API is now fully RESTful, making it easier to use with Angular.js, Ember.js, and other client-side content extraction and display tools. 3. Support for Symfony2. Symfony 2 is an up-to-date, object-oriented PHP framework, well known for customer relationship management (CRM) integration. 4. Twig support. Twig is a frontend library and template engine that eliminates some disadvantages of pure PHP while embracing the latest PHP standards. 5. Security improvements. New features offer additional ways to make systems more secure.
  • 5. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in Drupal 8 ● Planning Site Architecture ● Replacing Your Web Server ● Drupal Specifics - Drupal 8 Configuration ● Caching - Why cache with NGINX? - Microcaching - Cache Purging with NGINX Plus ● Reverse Proxy Server - Load Balancing - Session Persistence - Bonus: SSL/TLS and HTTP/2 ● Questions?
  • 6. MORE INFORMATION AT NGINX.COM Planning Your Site Architecture 1. Current architecture. Evaluate your current site traffic and performance. 2. Goals. Immediate problems, future growth 3. Estimate impact of changes. Open source NGINX or NGINX Plus as web server, reverse proxy server, load balancer, more. 4. Plan for growth. Estimate likely and possible growth and speed of growth. 5. Factor in the cloud. Use cloud from scratch, expand into the cloud, move into the cloud.
  • 7. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in Drupal 8 ● Planning Site Architecture ● Replacing Your Web Server ● Drupal Specifics - Drupal 8 Configuration ● Caching - Why cache with NGINX? - Microcaching - Cache Purging with NGINX Plus ● Reverse Proxy Server - Load Balancing - Session Persistence - Bonus: SSL/TLS and HTTP/2 ● Questions?
  • 8. MORE INFORMATION AT NGINX.COM Replacing Your Web Server 1. Replace Apache with NGINX or NGINX Plus. Immediate performance fix. Enables caching for static and dynamic content. (More on this soon.) Does not enable multiple app servers. 2. More performance on same hardware. Event loop replaces thread-per-connection, solves C10K problem. 3. Requires new server configuration. Replace familiar Apache configuration with tighter, more efficient (IMHO) NGINX configuration. 4. Independent of NGINX as reverse proxy server. You can use NGINX as a reverse proxy server with or without using NGINX as your web server; very flexible.
  • 9. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in Drupal 8 ● Planning Site Architecture ● Replacing Your Web Server ● Drupal Specifics - Drupal 8 Configuration ● Caching - Why cache with NGINX? - Microcaching - Cache Purging with NGINX Plus ● Reverse Proxy Server - Load Balancing - Session Persistence - Bonus: SSL/TLS and HTTP/2 ● Questions?
  • 10. MORE INFORMATION AT NGINX.COM NGINX configuration for Drupal • Minor changes to nginx.conf for Drupal 8 • Mostly related to update.php front controller • Sample configuration available on NGINX wiki • https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/
  • 11. MORE INFORMATION AT NGINX.COM Change #1: Accommodating update.php front controller location ~ '.php$ { ... } location ~ '.php$|^/update.php' { ... } • To accommodate URIs such as: /update.php/selection • Without this change NGINX will return a 404 error • Less strict (and more future proof) alternative: • Will match (and break) legacy Drupal URIs such as /blog/index.php/legacy location ~ '.php$(/|$) {
  • 12. MORE INFORMATION AT NGINX.COM Change #2: Non-greedy match fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_split_path_info ^(.+?.php)(|/.*)$; • To accommodate URIs such as: /core/authorize.php/core/authorize.php • Without this change NGINX will return a 404 error • Greedy match (left side) means entire URI will be SCRIPT_FILENAME • Non-greedy match (right side) means first authorize.php will be matched
  • 13. MORE INFORMATION AT NGINX.COM Change #3: Default location location / { try_files $uri @rewrite; } location /{ try_files $uri /index.php?$query_string; } • Change was made for Drupal 7 • Older version can cause query string to be altered
  • 14. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in Drupal 8 ● Planning Site Architecture ● Replacing Your Web Server ● Drupal Specifics - Drupal 8 Configuration ● Caching - Why cache with NGINX? - Microcaching - Cache Purging with NGINX Plus ● Reverse Proxy Server - Load Balancing - Session Persistence - Bonus: SSL/TLS and HTTP/2 ● Conclusion ● Questions?
  • 15. MORE INFORMATION AT NGINX.COM Why Cache with NGINX? Source: http://bbc.in/1O8qHbi
  • 16. MORE INFORMATION AT NGINX.COM Microcaching with NGINX • Cache content for a short time, as little as 1 second • Site content is out of date for max 1 second • Significant performance gains even for that short of a time
  • 17. MORE INFORMATION AT NGINX.COM Microcaching with NGINX proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2 inactive=600s max_size=100m; server { proxy_cache cache; proxy_cache_valid 200 1s; ... } • Cache 200 responses for 1 second
  • 18. MORE INFORMATION AT NGINX.COM Optimized Microcaching with NGINX server { proxy_cache cache; proxy_cache_valid 200 1s; proxy_cache_lock on; proxy_cache_use_stale updating; ... } • proxy_cache_lock – If multiple simultaneous requests for the same uncached or stale content, only one request allowed through. Other is queued. • proxy_cache_use_stale – Serve stale content when while cached entry is being updated
  • 19. MORE INFORMATION AT NGINX.COM Cache Purging with NGINX Plus proxy_cache_path /tmp/cache keys_zone=mycache:10m levels=1:2 inactive=60s; map $request_method $purge_method { PURGE 1; default 0; } server { proxy_cache mycache; proxy_cache_purge $purge_method; } $ curl -X PURGE -D – "http://www.example.com/*" HTTP/1.1 204 No Content …
  • 20. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in Drupal 8 ● Planning Site Architecture ● Replacing Your Web Server ● Drupal Specifics - Drupal 8 Configuration ● Caching - Why cache with NGINX? - Microcaching - Cache Purging with NGINX Plus ● Reverse Proxy Server - Load Balancing - Session Persistence - Bonus: SSL/TLS and HTTP/2 ● Questions?
  • 21. MORE INFORMATION AT NGINX.COM Load Balancing with NGINX
  • 22. MORE INFORMATION AT NGINX.COM Session Persistence with NGINX Plus • Stick client to the same server for duration of a session • Multiple methods: • NGINX tracks application session cookie: PHPSESSIONID • NGINX inserts its own cookie • Stick Route: Persistence based on cookie, HTTP header, etc. • IP Hash (Available in Open Source) • Session Draining: Gracefully remove servers from the load balancing pool
  • 23. MORE INFORMATION AT NGINX.COM SSL offloading with NGINX
  • 24. MORE INFORMATION AT NGINX.COM HTTP/2 with NGINX NGINX translates HTTP/2 to the language your application speaks
  • 25. MORE INFORMATION AT NGINX.COM Agenda ● What’s New in Drupal 8 ● Planning Site Architecture ● Replacing Your Web Server ● Drupal Specifics - Drupal 8 Configuration ● Caching - Why cache with NGINX? - Microcaching - Cache Purging with NGINX Plus ● Reverse Proxy Server - Load Balancing - Session Persistence - Bonus: SSL/TLS and HTTP/2 ● Questions?