Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Intro to Nginx
Search
Martin Loy
July 06, 2013
Technology
210
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Intro to Nginx
slides from my palestra @fisl14 on Porto Alegre
Martin Loy
July 06, 2013
More Decks by Martin Loy
See All by Martin Loy
NGINX for Fun & Profit
tombar
1
190
Other Decks in Technology
See All in Technology
コンテナ運用におけるネットワーク・コンテナコストの削減方法/How to Reduce Network and Container Costs in Container Operations
masakiokuda
1
240
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
190
Active Record Connection Adaptersにおける長年の課題に再び取り組む
yahonda
0
170
Classmethod Company Deck
satoshi7
1
710
"優秀な誰か"の下位互換にならないために
yut0naga1_fa
1
1.8k
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
6
5k
DGX Spark でどこまでハッキングができるのか?
kash1064
3
1.3k
夫婦で子育てするための育児標準化
codmoninc
PRO
0
370
Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
1
600
Gemini Intelligence 入門 ― AppFunctions と Gemini Nano
takuroabe
0
270
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
900
『SAR衛星データ解析入門』のご紹介とその応用
syuchimu
0
120
Featured
See All Featured
Discover your Explorer Soul
emna__ayadi
2
1.3k
The agentic SEO stack - context over prompts
schlessera
0
970
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
990
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
780
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
310
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Navigating Weather and Climate Data
rabernat
0
560
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
750
Transcript
Just a friendly disclaimer before we start.
Que e isso cara? #Fisl14, @MartinLoy
$ ls -l /palestras/nx/topics/* - apropos nginx - diff apache
nginx - config && syntax; - locations - proxy module - upstream module - using (php|python|ruby|websockets|*) - good practices && debugging tips - extras
Rise up!
$ apropos nginx - Small, powerful, scalable web|proxy server. -
Russian engineering. - BSD license. - Market Share 14.3% - It's pronounced “engine X” - Also an e-mail (imap|pop3) proxy.
$ diff apache nginx Apache prefork|worker|events* Modular (a2enmod) .htaccess Nginx
Async I/O, Event Loop Recompile to add* Configuration syntax & Rewrite Rules
Config && syntax;
$ man nginx.conf 3 main contexts http | server |
location variables and methods are lowercases and only support a-z and underscore set $var foo; set_header X-Example bar; http://wiki.nginx.org/Http{X}Module#{method}
@ http://wiki.nginx.org/HttpCoreModule#server_name server { server_name example.com; server_name a.com b.com; server_name
*.test.com; server_name _; }
@ http://wiki.nginx.org/HttpCoreModule#listen server { server_name *.test.com; listen localhost:8000; listen 127.0.0.1:443
ssl; listen 8000 default; listen *:8000; listen unix:/tmp/nginx.sock; }
@ http://wiki.nginx.org/HttpCoreModule#root server { server_name *.test.com; listen 127.0.0.1:8000; root /var/www/test;
access_log /var/log/nginx/acces.log; }
Locations
@ http://wiki.nginx.org/HttpCoreModule#location location = /admin { ... } /admin location
/ { ... } /index.html /example/test.html /match.any location /docs { ... } /docs/example.html location ^~ /images { ... } /images/avatar.gif location ~* (jpg|gif|png) { ... } /docs/1.gif
$ locations > mod_rewrite location /imgs { if ($http_user_agent ~
MSIE) { rewrite ^ http://disney.com? permanent; } try_files $uri $uri/ /error.gif; }
Dynamic Content
$ Proxy Module location / { proxy_set_header Host $host; proxy_pass
http://myBackend/app; proxy_redirect /app /; proxy_read_timeout 30s; } @ http://wiki.nginx.org/HttpProxyModule
Caching with nginx location / { proxy_pass http://myBackend; proxy_cache_valid 200
301 302 2h; proxy_cache_valid any 1m; proxy_cache_bypass $nocache_cookie; proxy_cache_key "$user_cookie$host$uri"; proxy_ignore_headers Cache-Control; } proxy_cache_use_stale error | timeout | updating | http_500 | http_502 | http_503 | http_404
$ Upstream Module upstream myBackendFarm { server 10.0.1.1 weight=2; server
10.0.1.2 weight=10 keepalive=5; server 10.0.1.3 down; server 10.0.1.4 max_fails=3 fail_timeout=5s; server 10.0.1.5 backup; [ fair | hash | sticky | + ] } @ http://wiki.nginx.org/HttpUpstreamModule
$ use (php|python|ruby|*) proxy_pass | fastcgi_pass | uwsgi_pass .php php-fpm
5.3.2+ .py wsgi, passenger, gunicorn. .rb rack, passenger, unicorn, thin, goliath. .* (http|socket)
$ nginx && websockets location /chat { proxy_pass http://myBackend; proxy_http_version
1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } @ http://nginx.org/en/docs/http/websocket.html
Good Practices & Debugging tips
Configuration Tips $ /etc/init.d/nginx configtest # use some extra headers
to help you out add_header X-foo $var; # nginx built in debug_connection debug_connection 127.0.0.1; @ http://wiki.nginx.org/IfIsEvil
@ http://wiki.nginx.org/HttpLogModule#log_format log_format multidomain-multiproxy-geoip $host - { combined apache log
format } - Cache: $upstream_cache_status $upstream_status $upstream_response_time $upstream_addr - Geo: $geoip_city_country_code $geoip_region
Cli tools $ tail -f /var/log/nginx/*error.log $ w3m -dump_head http://myBackend/img/a.gif
Content-Type: image/gif Last-Modified: Fri, 28 Jun 2013 15:57:46 GMT Cache-Control: max-age=864000 ETag: "e4f5659cd8bfb08fec2dc98e8450c414" Expires: Wed, 10 Jul 2013 07:24:03 GMT $ wget http://127.0.0.1/nx_stub -O - Active connections: 2676 server accepts handled requests 84315896 84315896 189890279 Reading: 204 Writing: 13 Waiting: 2459
@ http://wiki.nginx.org/3rdPartyModules
# Cache Backends redis, memcache, mongo, purge # Security mod_security,
naxsi, http pam # Media image filter, mp4, thumb extractor # Misc php, form parser, rdd, download $ ls -l /nx/3rdPartyMods/* # Optimizers pagespeed, css, js min # Monitoring statsd, sflow, syslog # Real FUN ! lua, perl, python, javascript # more awesomeness openresty, upload, push/comet
ASK me Anything NGINX related! & GET /some-alfajores
contact me @martinloy | github.com/tombar
@martinloy github.com/tombar