SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
NGINX CAN DO THAT? 
TEST DRIVE YOUR CONFIG FILE! 
Presented By Jeff Anderson / @programm3rq / programmerq
MY BACKGROUND 
Linux/Apache since middle school. webdev since I was 10. 
Worked with Apache professionally since my first job in the 
industry. 
Started using nginx for my first project when I started at HP 
back in 2010. 
I have been using nginx every chance since.
NGINX CAN DO THAT? 
More often than not... YES!
STORY TIME 
http://www.example.com/ server layout diagram.
http://www.example.com/ nginx config file. 
upstream backend { 
server app1:8000; 
server app2:8000; 
server app3:8000; 
} server { 
server_name www.example.com; 
location / { 
proxy_pass http://backend; 
} 
}
But a simple nginx config file can be added to. 
You can only keep your config file simple for so long while taking 
on additional features.
REQUIREMENTS 
Multi-environment (staging, production, dev, test, qa, etc...) 
Caching - some content will be cached by nginx 
IP-based Access Control - some URLs will be protected 
Maintenance Page - for site maintenance (scheduled or 
otherwise) 
Multiple upstreams - feature B is done by team X in language Y
REQUIREMENTS (CONTINUED) 
NON-PRODUCTION-SPECIFIC REQUIREMENTS 
Caching - developers want to toggle caching features for 
development. 
Maintenance Page - we won't ever use this feature outside 
production. 
Keep out the Internet! - Our QA team does not have VPN 
access, but needs to access our site still. Basic Auth.
REQUIREMENTS (CONTINUED) 
PRODUCTION-SPECIFIC REQUIREMENTS (STAGING TOO) 
Additional Nodes - More traffic and real customers means 
more resources. 
Geographic Redundancy - Two or more datacenters. 
CDN - Our nginx servers will be behind Akamai or another 
CDN to speed up asset delivery. 
SSL - https needs to be on.
REQUIREMENTS (CONTINUED) 
THESE TRICKLE IN AS PEOPLE FIND THINGS BROKEN. 
Maintenance Page (cont'd) - Make sure the maintenance page 
does not block /admin/. 
Basic Auth - Should not block /api/callbacks/. 
Block some URLs - Appserver URLs for healthchecks should 
not be served via nginx.
TESTING SOFTWARE 
"We will write tests before we code, minute 
by minute. We will preserve these tests 
forever, and run them all together frequently. 
We will also derive tests from the customer's 
perspective." 
- Kent Beck "eXtreme Programming 
explained" Chapter 18 heading
TEST ALL THE THINGS!
WRITING TESTS IS AWESOME!
TEST NGINX?
CONTINUOUS INTEGRATION
CONTINUOUS INTEGRATION 
I have the most experience with Jenkins.
INFRASTRUCTURE TESTS
INFRASTRUCTURE TESTS 
Test Kitchen (aka KitchenCI) was written to enable automated 
testing of chef cookbooks and recipes. 
Runs tests inside virtualbox, vmware, aws, digitalocean, 
docker, and more 
Can run chef, puppet, salt, and more 
ability to use Bats, shUnit2, rspec, serverspec, and more
BACK TO OUR ORIGINAL EXAMPLE: 
http://www.example.com/ server layout diagram.
BACK TO OUR ORIGINAL EXAMPLE: 
http://www.example.com/ nginx config file. 
upstream backend { 
server app1:8000; 
server app2:8000; 
server app3:8000; 
} server { 
server_name www.example.com; 
location / { 
proxy_pass http://backend; 
}
How do we make this support multiple environments?
CONFIG GENERATORS 
What if we want to dynamically build the config file? 
upstream backend { 
<% upstreams.each do |host| %> 
server <%= host %>; 
<% end %> 
} server { 
server_name <%= server_name %>; 
location / { 
proxy_pass http://backend; 
} 
}
TESTING STRATEGY 1 
Mock data to be used by the config generator 
run nginx -t against the result. 
make assertions with regex 
compare all generated output to a "golden image" (approvals)
Mock data 
[{ 
'environment': 'production', 
'server_name': 'www.example.com', 
'upstreams': ['app1:8000', 
'app2:8000', 
'app3:8000']}, 
{ 
'environment': 'staging', 
'server_name': 'staging.example.com', 
'upstreams': ['stage_app1:8000', 
'stage_app2:8000', 
'stage_app3:8000']} 
]
That should produce the following configuration files: 
upstream backend { 
server app1:8000; 
server app2:8000; 
server app3:8000; 
} server { 
server_name www.example.com; 
location / { 
proxy_pass http://backend; 
} 
} 
upstream backend { 
server stage_app1:8000; 
server stage_app2:8000; 
server stage_app3:8000; 
} 
server { 
server_name staging.example.com; 
location / { 
proxy_pass http://backend; 
} 
}
WORKFLOW FOR STRATEGY #1 
Check in golden copies. 
Make a change to the template. 
If you introduce a syntax error, you are notified. 
Test will fail if output is different than golden. 
Examine differences between the new and the golden. 
"Approve" the changes by checking in the changes as the new 
golden. 
This is known as "approvals" testing.
A MORE COMPLEX EXAMPLE: 
Mock data 
[{ 
'environment': 'production', 
'server_name': 'www.example.com', 
'upstreams': ['app1:8000', 
'app2:8000', 
'app3:8000'], 
'no_access_locations': ['/api/healthcheck'], 
'basic_auth': false, 
'basic_auth_excluded_paths': []}, 
{ 
'environment': 'staging', 
'server_name': 'staging.example.com', 
'upstreams': ['stage_app1:8000', 
'stage_app2:8000', 
'stage_app3:8000'], 
'no_access_locations': ['/api/healthcheck'], 
'basic_auth': {'file': '.htpasswd'}, 
'basic_auth_excluded_paths': ['/api/callback', '/api/rss'] 
}]
A MORE COMPLEX EXAMPLE: 
upstream backend { 
<% upstreams.each do |host| %> 
server <%= host %>; 
<% end %> 
} server { 
server_name <%= server_name %>; 
error_page 503 /maintenance.html; 
error_page 502 /maintenance.html; 
error_page 500 /500.html; 
error_page 504 /504.html; 
error_page 404 /404.html; 
root /www/<%= server_name %>; 
proxy_intercept_errors on; 
proxy_connect_timeout 2; 
<% no_access_locations.each do |blocked| %> 
location ^~ <%= blocked %> { 
return 404; 
} 
<% end %> 
location / { 
if ( -f $request-filename ) { 
break; 
} 
if ( -e $document_root/maintenance-on) { 
return 503; 
} 
try_files $uri @backend; 
<% if basic_auth %>
TESTING STRATEGY 2 
Generate the config. 
Actually turn on nginx. 
send requests to it and assert it does the right thing. 
These are integration tests.
INTEGRATION TESTING 
Assert that ip-address-based access works. 
{"server_name": "test-app.example.com", 
"ip_access": [{"127.0.0.1": ["/admin"]}]} 
assert `curl -kIs -H 'Host: test-app.example.com' http://192.168.0.2/admin  
| head -n 1 | awk '{print $2}'` == 404 
assert `curl -kIs -H 'Host: test-app.example.com' http://127.0.0.1/admin  
| head -n 1 | awk '{print $2}'` == 502
INTEGRATION TESTING 
Assert that the existence of 
$document_root/maintenance-on turns on the 
maintenance page. 
rm -f /www/maintenance-on 
assert `curl -kIs -H 'Host: example.com' http://127.0.0.1/  
| head -n 1 | awk '{print $2}'` == 502 
touch /www/maintenance-on 
assert `curl -kIs -H 'Host: example.com' http://127.0.0.1/  
| head -n 1 | awk '{print $2}' == 503 
rm -f /www/maintenance-on
ADDITIONAL METHODS OF TESTING 
more integration options 
run nginx using strace and examine strace output. 
run nginx inside a proxifier and intercept nginx upstream 
requests. 
configure nginx to use a dummy webserver and examine its 
upstream requests.
LOOKING FORWARD 
Using a web server testing framework instead of curl requests. 
"native" testing framework - maybe an extension that runs 
inside nginx? 
Something else? maybe there's an even better method that I 
have not even thought of.
DEMO TIME 
REQUIREMENTS 
There are three separate applications that share an 
authentication service. 
The NOC must ssh in to 10 different nginx servers and touch 
/www/maintenance-on. 
Management wants maintenance page up faster during an 
outage.
BUTTONS!
POSSIBLE IMPLEMENTATIONS 
admin.example.com to ssh in to nginx servers?...Nope. 
admin.example.com to trigger chef runs?...Nope. 
admin.example.com to hit nginx directly?...Yes!
HITTING NGINX 
I want to touch /www/maintenance-on 
I want only admin.example.com's server to be able to do it. 
Webdav PUT/DELETE seems like a good fit. 
Security team wants webdav to appear disabled to scanners.
THE END 
Presented By Jeff Anderson / @programm3rq / programmerq 
Slides created using reveal.js - 
Jenkins - 
Chef - 
Berkshelf - 
Test Kitchen / KitchenCI - 
BATS - 
Docker - 
cURL - 
nginx - 
http://lab.hakim.se/reveal-js/#/ 
http://jenkins-ci.org/ 
https://www.getchef.com/ 
http://berkshelf.com/ 
http://kitchen.ci/ 
https://github.com/sstephenson/bats 
https://www.docker.com/ 
http://curl.haxx.se/ 
http://nginx.org/

Mais conteúdo relacionado

Mais procurados

5 things you didn't know nginx could do velocity
5 things you didn't know nginx could do   velocity5 things you didn't know nginx could do   velocity
5 things you didn't know nginx could do velocitysarahnovotny
 
Load Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINXLoad Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINXNGINX, Inc.
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXNGINX, Inc.
 
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Nginx A High Performance Load Balancer, Web Server & Reverse ProxyNginx A High Performance Load Balancer, Web Server & Reverse Proxy
Nginx A High Performance Load Balancer, Web Server & Reverse ProxyAmit Aggarwal
 
Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Trygve Vea
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more DockerSarah Novotny
 
NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX, Inc.
 
NGINX High-performance Caching
NGINX High-performance CachingNGINX High-performance Caching
NGINX High-performance CachingNGINX, Inc.
 
under the covers -- chef in 20 minutes or less
under the covers -- chef in 20 minutes or lessunder the covers -- chef in 20 minutes or less
under the covers -- chef in 20 minutes or lesssarahnovotny
 
Delivering High Performance Websites with NGINX
Delivering High Performance Websites with NGINXDelivering High Performance Websites with NGINX
Delivering High Performance Websites with NGINXNGINX, Inc.
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx InternalsJoshua Zhu
 
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015Fastly
 
Rate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusRate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusNGINX, Inc.
 
Mike Guthrie - Revamping Your 10 Year Old Nagios Installation
Mike Guthrie - Revamping Your 10 Year Old Nagios InstallationMike Guthrie - Revamping Your 10 Year Old Nagios Installation
Mike Guthrie - Revamping Your 10 Year Old Nagios InstallationNagios
 
Introduction to NGINX web server
Introduction to NGINX web serverIntroduction to NGINX web server
Introduction to NGINX web serverMd Waresul Islam
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesSeveralnines
 
Using NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheUsing NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheKevin Jones
 
Janice Singh - Writing Custom Nagios Plugins
Janice Singh - Writing Custom Nagios PluginsJanice Singh - Writing Custom Nagios Plugins
Janice Singh - Writing Custom Nagios PluginsNagios
 

Mais procurados (20)

5 things you didn't know nginx could do velocity
5 things you didn't know nginx could do   velocity5 things you didn't know nginx could do   velocity
5 things you didn't know nginx could do velocity
 
Load Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINXLoad Balancing and Scaling with NGINX
Load Balancing and Scaling 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
 
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Nginx A High Performance Load Balancer, Web Server & Reverse ProxyNginx A High Performance Load Balancer, Web Server & Reverse Proxy
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
 
Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Docker
 
NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load Balancing
 
Nginx
NginxNginx
Nginx
 
NGINX High-performance Caching
NGINX High-performance CachingNGINX High-performance Caching
NGINX High-performance Caching
 
under the covers -- chef in 20 minutes or less
under the covers -- chef in 20 minutes or lessunder the covers -- chef in 20 minutes or less
under the covers -- chef in 20 minutes or less
 
Nginx dhruba mandal
Nginx dhruba mandalNginx dhruba mandal
Nginx dhruba mandal
 
Delivering High Performance Websites with NGINX
Delivering High Performance Websites with NGINXDelivering High Performance Websites with NGINX
Delivering High Performance Websites with NGINX
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx Internals
 
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
 
Rate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusRate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX Plus
 
Mike Guthrie - Revamping Your 10 Year Old Nagios Installation
Mike Guthrie - Revamping Your 10 Year Old Nagios InstallationMike Guthrie - Revamping Your 10 Year Old Nagios Installation
Mike Guthrie - Revamping Your 10 Year Old Nagios Installation
 
Introduction to NGINX web server
Introduction to NGINX web serverIntroduction to NGINX web server
Introduction to NGINX web server
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - Slides
 
Using NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheUsing NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content Cache
 
Janice Singh - Writing Custom Nagios Plugins
Janice Singh - Writing Custom Nagios PluginsJanice Singh - Writing Custom Nagios Plugins
Janice Singh - Writing Custom Nagios Plugins
 

Semelhante a NGINX Can Do That? Test Drive Your Config File!

Making Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixMaking Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixDiana Tkachenko
 
NLIT 2011: Chef & Capistrano
NLIT 2011: Chef & CapistranoNLIT 2011: Chef & Capistrano
NLIT 2011: Chef & Capistranonickblah
 
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 JonesOrtus Solutions, Corp
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and MaintenanceJazkarta, Inc.
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile InfrastructuresAntons Kranga
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETGianluca Carucci
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardSV Ruby on Rails Meetup
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
DevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office HoursDevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office HoursAmazon Web Services
 
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014Rackspace Academy
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetupNicole Johnson
 
Automating AWS Compliance with InSpec
Automating AWS Compliance with InSpec Automating AWS Compliance with InSpec
Automating AWS Compliance with InSpec Matt Ray
 
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltStack
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)Wesley Beary
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slidesDocker, Inc.
 
AWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaAWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaManish Pandit
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application ServerPhil Windley
 

Semelhante a NGINX Can Do That? Test Drive Your Config File! (20)

Making Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixMaking Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch Fix
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
NLIT 2011: Chef & Capistrano
NLIT 2011: Chef & CapistranoNLIT 2011: Chef & Capistrano
NLIT 2011: Chef & Capistrano
 
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
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile Infrastructures
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
DevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office HoursDevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office Hours
 
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetup
 
Automating AWS Compliance with InSpec
Automating AWS Compliance with InSpec Automating AWS Compliance with InSpec
Automating AWS Compliance with InSpec
 
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
AWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaAWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and Java
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 

Último

SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 

Último (20)

SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 

NGINX Can Do That? Test Drive Your Config File!

  • 1. NGINX CAN DO THAT? TEST DRIVE YOUR CONFIG FILE! Presented By Jeff Anderson / @programm3rq / programmerq
  • 2. MY BACKGROUND Linux/Apache since middle school. webdev since I was 10. Worked with Apache professionally since my first job in the industry. Started using nginx for my first project when I started at HP back in 2010. I have been using nginx every chance since.
  • 3. NGINX CAN DO THAT? More often than not... YES!
  • 4. STORY TIME http://www.example.com/ server layout diagram.
  • 5. http://www.example.com/ nginx config file. upstream backend { server app1:8000; server app2:8000; server app3:8000; } server { server_name www.example.com; location / { proxy_pass http://backend; } }
  • 6. But a simple nginx config file can be added to. You can only keep your config file simple for so long while taking on additional features.
  • 7. REQUIREMENTS Multi-environment (staging, production, dev, test, qa, etc...) Caching - some content will be cached by nginx IP-based Access Control - some URLs will be protected Maintenance Page - for site maintenance (scheduled or otherwise) Multiple upstreams - feature B is done by team X in language Y
  • 8. REQUIREMENTS (CONTINUED) NON-PRODUCTION-SPECIFIC REQUIREMENTS Caching - developers want to toggle caching features for development. Maintenance Page - we won't ever use this feature outside production. Keep out the Internet! - Our QA team does not have VPN access, but needs to access our site still. Basic Auth.
  • 9. REQUIREMENTS (CONTINUED) PRODUCTION-SPECIFIC REQUIREMENTS (STAGING TOO) Additional Nodes - More traffic and real customers means more resources. Geographic Redundancy - Two or more datacenters. CDN - Our nginx servers will be behind Akamai or another CDN to speed up asset delivery. SSL - https needs to be on.
  • 10. REQUIREMENTS (CONTINUED) THESE TRICKLE IN AS PEOPLE FIND THINGS BROKEN. Maintenance Page (cont'd) - Make sure the maintenance page does not block /admin/. Basic Auth - Should not block /api/callbacks/. Block some URLs - Appserver URLs for healthchecks should not be served via nginx.
  • 11. TESTING SOFTWARE "We will write tests before we code, minute by minute. We will preserve these tests forever, and run them all together frequently. We will also derive tests from the customer's perspective." - Kent Beck "eXtreme Programming explained" Chapter 18 heading
  • 12. TEST ALL THE THINGS!
  • 13. WRITING TESTS IS AWESOME!
  • 16. CONTINUOUS INTEGRATION I have the most experience with Jenkins.
  • 18. INFRASTRUCTURE TESTS Test Kitchen (aka KitchenCI) was written to enable automated testing of chef cookbooks and recipes. Runs tests inside virtualbox, vmware, aws, digitalocean, docker, and more Can run chef, puppet, salt, and more ability to use Bats, shUnit2, rspec, serverspec, and more
  • 19. BACK TO OUR ORIGINAL EXAMPLE: http://www.example.com/ server layout diagram.
  • 20. BACK TO OUR ORIGINAL EXAMPLE: http://www.example.com/ nginx config file. upstream backend { server app1:8000; server app2:8000; server app3:8000; } server { server_name www.example.com; location / { proxy_pass http://backend; }
  • 21. How do we make this support multiple environments?
  • 22. CONFIG GENERATORS What if we want to dynamically build the config file? upstream backend { <% upstreams.each do |host| %> server <%= host %>; <% end %> } server { server_name <%= server_name %>; location / { proxy_pass http://backend; } }
  • 23. TESTING STRATEGY 1 Mock data to be used by the config generator run nginx -t against the result. make assertions with regex compare all generated output to a "golden image" (approvals)
  • 24. Mock data [{ 'environment': 'production', 'server_name': 'www.example.com', 'upstreams': ['app1:8000', 'app2:8000', 'app3:8000']}, { 'environment': 'staging', 'server_name': 'staging.example.com', 'upstreams': ['stage_app1:8000', 'stage_app2:8000', 'stage_app3:8000']} ]
  • 25. That should produce the following configuration files: upstream backend { server app1:8000; server app2:8000; server app3:8000; } server { server_name www.example.com; location / { proxy_pass http://backend; } } upstream backend { server stage_app1:8000; server stage_app2:8000; server stage_app3:8000; } server { server_name staging.example.com; location / { proxy_pass http://backend; } }
  • 26. WORKFLOW FOR STRATEGY #1 Check in golden copies. Make a change to the template. If you introduce a syntax error, you are notified. Test will fail if output is different than golden. Examine differences between the new and the golden. "Approve" the changes by checking in the changes as the new golden. This is known as "approvals" testing.
  • 27. A MORE COMPLEX EXAMPLE: Mock data [{ 'environment': 'production', 'server_name': 'www.example.com', 'upstreams': ['app1:8000', 'app2:8000', 'app3:8000'], 'no_access_locations': ['/api/healthcheck'], 'basic_auth': false, 'basic_auth_excluded_paths': []}, { 'environment': 'staging', 'server_name': 'staging.example.com', 'upstreams': ['stage_app1:8000', 'stage_app2:8000', 'stage_app3:8000'], 'no_access_locations': ['/api/healthcheck'], 'basic_auth': {'file': '.htpasswd'}, 'basic_auth_excluded_paths': ['/api/callback', '/api/rss'] }]
  • 28. A MORE COMPLEX EXAMPLE: upstream backend { <% upstreams.each do |host| %> server <%= host %>; <% end %> } server { server_name <%= server_name %>; error_page 503 /maintenance.html; error_page 502 /maintenance.html; error_page 500 /500.html; error_page 504 /504.html; error_page 404 /404.html; root /www/<%= server_name %>; proxy_intercept_errors on; proxy_connect_timeout 2; <% no_access_locations.each do |blocked| %> location ^~ <%= blocked %> { return 404; } <% end %> location / { if ( -f $request-filename ) { break; } if ( -e $document_root/maintenance-on) { return 503; } try_files $uri @backend; <% if basic_auth %>
  • 29. TESTING STRATEGY 2 Generate the config. Actually turn on nginx. send requests to it and assert it does the right thing. These are integration tests.
  • 30. INTEGRATION TESTING Assert that ip-address-based access works. {"server_name": "test-app.example.com", "ip_access": [{"127.0.0.1": ["/admin"]}]} assert `curl -kIs -H 'Host: test-app.example.com' http://192.168.0.2/admin | head -n 1 | awk '{print $2}'` == 404 assert `curl -kIs -H 'Host: test-app.example.com' http://127.0.0.1/admin | head -n 1 | awk '{print $2}'` == 502
  • 31. INTEGRATION TESTING Assert that the existence of $document_root/maintenance-on turns on the maintenance page. rm -f /www/maintenance-on assert `curl -kIs -H 'Host: example.com' http://127.0.0.1/ | head -n 1 | awk '{print $2}'` == 502 touch /www/maintenance-on assert `curl -kIs -H 'Host: example.com' http://127.0.0.1/ | head -n 1 | awk '{print $2}' == 503 rm -f /www/maintenance-on
  • 32. ADDITIONAL METHODS OF TESTING more integration options run nginx using strace and examine strace output. run nginx inside a proxifier and intercept nginx upstream requests. configure nginx to use a dummy webserver and examine its upstream requests.
  • 33. LOOKING FORWARD Using a web server testing framework instead of curl requests. "native" testing framework - maybe an extension that runs inside nginx? Something else? maybe there's an even better method that I have not even thought of.
  • 34. DEMO TIME REQUIREMENTS There are three separate applications that share an authentication service. The NOC must ssh in to 10 different nginx servers and touch /www/maintenance-on. Management wants maintenance page up faster during an outage.
  • 36. POSSIBLE IMPLEMENTATIONS admin.example.com to ssh in to nginx servers?...Nope. admin.example.com to trigger chef runs?...Nope. admin.example.com to hit nginx directly?...Yes!
  • 37. HITTING NGINX I want to touch /www/maintenance-on I want only admin.example.com's server to be able to do it. Webdav PUT/DELETE seems like a good fit. Security team wants webdav to appear disabled to scanners.
  • 38. THE END Presented By Jeff Anderson / @programm3rq / programmerq Slides created using reveal.js - Jenkins - Chef - Berkshelf - Test Kitchen / KitchenCI - BATS - Docker - cURL - nginx - http://lab.hakim.se/reveal-js/#/ http://jenkins-ci.org/ https://www.getchef.com/ http://berkshelf.com/ http://kitchen.ci/ https://github.com/sstephenson/bats https://www.docker.com/ http://curl.haxx.se/ http://nginx.org/