Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige

Hier ansehen

1 von 55 Anzeige

NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!

Herunterladen, um offline zu lesen

NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!

NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!

Anzeige
Anzeige

Weitere Verwandte Inhalte

Ähnlich wie NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる! (20)

Weitere von NGINX, Inc. (20)

Anzeige

Aktuellste (20)

NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!

  1. 1. NGINXセミナー(基本編) いまさら聞けないNGINXコンフィグなど基本がわかる︕ F5ネットワークスジャパン合同会社 Daiki KUBO | Solutions Engineer
  2. 2. ©2022 F5 2  Webサーバに対する一般的な理解  HTTPやTCP/IPに関する基本的な知識  ネットワークに関する基本的な理解  Linuxコマンドラインに関する知識 前提条件
  3. 3. ©2022 F5 3 Agenda  NGINXの紹介/アーキテクチャ  NGINXの基本設定  NGINX Web Server  NGINX Reverse Proxy
  4. 4. ©2022 F5 4 Module 1 NGINXの紹介/アーキテクチャ
  5. 5. ©2022 F5 5 Module 1 の目的 • 一般的な用途について • Open Source NGINX の特徴 • NGINX Plus の特徴 • NGINX のアーキテクチャ • NGINX の基本的なコマンドの実行
  6. 6. ©2022 F5 6 NGINX 製品 Delivering modern applications at scale across seamlessly across multi-cloud NGINX Plus All-In-One Software ロードバランサー、コンテンツキャッシュ、 Webサーバ 安定、高速、高機能 必要となるリソースは最小 NGINX Management Suite NGINX+統合管理ソフトウェア NGINX+のロードバランサやAPI Gateway、更にマルチクラウド環境に おいても容易に管理が可能。 GUI/CLIに加えAPIでの制御が可能 アプリケーションに特化した Web Application Firewall NGINX+にシームレスに統合可能な 新しいWAF。 F5の実績に基づき、 高速な高品質なWAFを実現 High quality Support NGINX App Protect
  7. 7. ©2022 F5 7 NGINX コンテナ環境向け製品 Delivering modern applications at scale across seamlessly across multi-cloud NGINX Service Mesh NGINX Plusで複雑な マイクロサービス、アプリケーション間の 通信問題を解決するシンプルな サービスメッシュソリューション。 Amazon EKS, Azure AKS対応 NGINX Ingress Controller Kubernetes環境への 外部アクセスをコントロール。 NGINX機能をIngressリソース を通じて管理可能。 NGINX App Protect対応 High quality Support
  8. 8. ©2022 F5 8 NGINX Product Portfolio Web KIC SP MS SP MS L7 LB NGINX Plus NGINX Management Suite NGINX Plus Web server NGINX Unit App server CODE CUSTOMER App L4-L7 LB API GW Per app WAF 高速・高品質 Web Server Web Application Server NGINX Plus Sidecar proxy SP MS Application高頻度のリリースを実現する、 高い柔軟性・効率・品質のアプリケーション基盤 Container Ingress Service Service Mesh L7 LB Reverse Proxy /Cache / API GW / Per app WAF MONOLOTHIC MICROSERVICES NGINX Plus K8s IC CI/CD DevSecOps
  9. 9. ©2022 F5 9 NGINX ご利用構成・特徴
  10. 10. ©2022 F5 10 NGINX : Web Server Static Content Module 2
  11. 11. ©2022 F5 11 NGINX : Reverse Proxy Server Database Server Application Server 1 Application Server 2 Module 3
  12. 12. ©2022 F5 12 NGINX : Load Balancer
  13. 13. ©2022 F5 13 NGINX Plus 追加機能 https://www.nginx.co.jp/products/products-nginx/ ロードバランシング 負荷分散アルゴリズム, セッション維持, アクティブヘルスチェック(TCP, HTTP, gRPC), DNSサービスディスカバリ 動的設定変更 REST API, アップストリーム, SSL証明書, Key-Valueストア, キャッシュ削除 監視 REST API, NGINX Plus ダッシュボード, Prometheus公式モジュール, OpenTracing公式モジュール DataDog/NewRelicエージェント対応 公式Dockerfile 公式ドキュメント, NGINX Plus Ingress Controller 高可用性とクラスタリング HA構成, ステート情報の共有, クラウド環境スケールアップ/ダウン 認証 OpenID, JWT, (ADFS, Amazon Cognito, Keycloak, Okta, OneLogin) Webアプリケーションファイアウォール NGINX App Protect 認定サードパーティ動的モジュール NGINX Brotli, GeoIP, GeoIP2, Lua, Image-Filter, RTMP, Cookie-Flag, HTTP Substitutions Filter, NGINX Developer Kit, Perl, Set-Misc, SPNEGO, XSLT
  14. 14. ©2022 F5 14 柔軟に拡張できる最高のパフォーマンス https://www.nginx.com/resources/datasheets/nginx-plus-sizing-guide/ https://www.nginx.com/blog/nginx-plus-sizing-guide-how-we-tested/ NGINXはCPU Core数に応じて通信の並列処理を実施します CPUコア数に応じてパフォーマンスが向上します 0 10000 20000 30000 40000 50000 60000 0 200000 400000 600000 800000 1000000 1200000 RPS ECC 2 CPU cores 4 GB RAM 4 CPU cores 4 GB RAM 8 CPU cores 4 GB RAM 16 CPU cores 4 GB RAM 32 CPU cores 8 GB RAM HARDWARE SPECS EXPECTED PERFORMANCE 2 CPU cores 4 GB RAM 2x1 GbE NIC 90,000 RPS 4,500 SSL TPS (ECC) 1 Gbps throughput 4 CPU cores 4 GB RAM 2x40 GbE NIC 175,000 RPS 8,500 SSL TPS (ECC) 5 Gbps throughput 8 CPU cores 4 GB RAM 2x40 GbE NIC 350,000 RPS 16,000 SSL TPS (ECC) 40 Gbps throughput 16 CPU cores 4 GB RAM 2x40 GbE NIC 650,000 RPS 30,000 SSL TPS (ECC) 40 Gbps throughput 32 CPU cores 8 GB RAM 4x40 GbE NIC 1,000,000 RPS 52,000 SSL TPS (ECC) 70 Gbps throughput 44 CPU cores 16 GB RAM 4x40 GbE NIC 1,200,000 RPS 64,000 SSL TPS (ECC) 70 Gbps throughput
  15. 15. ©2022 F5 15 NGINX 基本構成
  16. 16. ©2022 F5 16 NGINX Plus Architecture https://www.nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/ Processes • Master process • Child processes - Cache manager - Cache loader - Worker processes • Non-blocking I/O
  17. 17. ©2022 F5 17 Master Process demo
  18. 18. ©2022 F5 18 Child Process https://www.nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/ • Cache manager • Cache loader • Worker processes W W W W
  19. 19. ©2022 F5 19 Non-blocking I/O Time Blocking Non-blocking Get Account Fetch Web Page Get Account Fetch Web Page
  20. 20. ©2022 F5 20 NGINX Commands • NGINX versionの表示 $ nginx -v • config file syntaxの確認 $ nginx -t • 現在のconfigとconfig file syntaxの確認 $ nginx -T demo
  21. 21. ©2022 F5 21 Module 2 NGINXの基本設定 Web serverの設定 (listen, server_name, default_server)
  22. 22. ©2022 F5 22 Module 2 の目的 • NGINX configuration fileの確認 • configuration fileのcontexts, blocks, について • server の処理順序について • server_name , listen , default_serverの挙動について
  23. 23. ©2022 F5 23 初期Configration Fileの配置場所 • /etc/nginx/nginx.conf • /etc/nginx/conf.d/default.conf
  24. 24. ©2022 F5 24 Directives Directive: NGINXの動作を規定する • 文末はセミコロン「;」をつける Block – Directiveをまとめたもの • 中括弧「{}」で囲う server { listen 80; root /usr/share/nginx/html; } Server Block Start Listen Directive Root Directive End of Server Block
  25. 25. ©2022 F5 25 Directive Parameters Examples of listen directive parameters: listen 443 ssl; #Defines an HTTPS server on port 443 listen 443 ssl http2; #Allows HTTP/2 protocol for client HTTP requests listen 53 udp; #Defines UDP protocol for all port 53 traffic
  26. 26. ©2022 F5 26 Configration Contexts NGINX Configは、main, HTTP などのコンテキストを持つ 利用者が主に操作する場所は、 • Server context • Location context
  27. 27. ©2022 F5 27 Main Context • 最上位のdirectives • 記載内容の例 −worker processesの数 −NGINXのLinux username −File配置場所 −Error log −Process ID (PID)
  28. 28. ©2022 F5 28 Event Context • connection processing directivesを記述 • 記載内容の例 −worker processごとに処理す るコネクション数の指定 • 基本的にDefault値を使用 する
  29. 29. ©2022 F5 29 HTTP Context • NGINXがどのようにHTTP や HTTPSのconnectionを処理 するか定義 • log formatsや、locationの 指定 • include directiveを用いて conf.dよりconfig fileのロード をすることが可能
  30. 30. ©2022 F5 30 Server Context リクエストに応答するためのvirtual serverを定義 • Domain name • IP address • Unix socket
  31. 31. ©2022 F5 31 Location Context HTTP requestを更にどのように 取り扱うか定義 • request URIを基に定義 • pathを指定 • requestのPath文字列を一致をもとに制御
  32. 32. ©2022 F5 32 NGINX Default Parameter server { listen *:80; server_name “”; root html; index index.html; } demo
  33. 33. ©2022 F5 33 Requestを分解する
  34. 34. ©2022 F5 34 Server の選択 server { listen 127.0.0.1:80; server_name example.com; root /usr/share/nginx/html; } server { listen 127.0.0.2:80; server_name example.net; root /home/ubuntu/public_html; }
  35. 35. ©2022 F5 35 Listen Directive DIRECTIVE NGINXが待ち受ける内容 <no listen directive> 0.0.0.0:80 listen 127.0.0.1:8080; 127.0.0.1:8080 listen 127.0.0.2; 127.0.0.2:80 listen 80; 0.0.0.0:80 listen unix:/var/run/nginx.sock; 完全パスで指定したSocket Note: NGINX はIPv4と同時にIPv6で通信を受け付けます demo
  36. 36. ©2022 F5 36 server_name Directive server { listen 192.168.1.10; server_name www.example.org; ... } server { listen 192.168.1.10; server_name www.example.com; ... } Request: http://www.example.com
  37. 37. ©2022 F5 37 server_name 処理順序 1. 文字列の完全一致 2. Wild Cardを用いた文字列の前方一致 3. Wild Cardを用いた文字列の後方一致 4. 正規表現のはじめの一致
  38. 38. ©2022 F5 38 default_server Parameter server { listen 192.168.1.1; server_name www.example.*; } server { listen 192.168.1.1; server_name *.example.net; } server{ listen 192.168.1.1; server_name ~^(host1|host2).*¥.example¥.com$; } server { listen 192.168.1.1 default_server; error_page 404 /40x.html; }
  39. 39. ©2022 F5 39 Module Summary • listen directive:IP:Port を指定しVirtual Serverを設定します − NGINXはlisten directiveの足りないパラメータを補って処理します − IPアドレスのみ指定した場合、Portのみ指定した場合より優先されます • server_name directive:Host Headerの内容から複数のIP:Portで待ち 受けるVirtual Serverに対して通信を転送します − server_nameはロンゲストマッチにより処理されます • default_server:NGINXの処理でいずれのlisten/server_nameにも該当 しない場合、処理されます
  40. 40. ©2022 F5 40 Module 3 Reverse Proxy
  41. 41. ©2022 F5 41 Module 3 の目的 • Reverse ProxyとしてNGINXを設定する方法について
  42. 42. ©2022 F5 42 Reverse Proxy Serverとは? Internet Forward Proxy Reverse Proxy
  43. 43. ©2022 F5 43 proxy_pass Directive • 書式: proxy_pass <転送先>; • serverまたはlocationのコンテキスト内で使用する location / { proxy_pass http://192.4.1.4/application1; }
  44. 44. ©2022 F5 44 Pathを指定して通信を転送する – Replace(置換) demo Request: http://www.example.com/application1/usr1/index.php server { listen 80 default_server; location /application1 { proxy_pass http://192.168.1.2:8080/otherapp; } } 転送されるrequest: http://192.168.1.2:8080/otherapp/usr1/index.php
  45. 45. ©2022 F5 45 Pathを指定せず通信を転送する – Append(追加) Request: http://www.example.com/application2/usr2/index.php server { listen 80 default_server; location /application2 { proxy_pass http://192.168.1.2:8080; } } 転送されるrequest: http://192.168.1.2:8080/application2/usr2/index.php demo
  46. 46. ©2022 F5 46 NGINX 変数の書式 書式︓$<variable_name> http://nginx.org/en/docs/varindex.html Variable Name 意味 $remote_addr クライアントアドレス $server_port サーバポート $cookie_<name> 指定したCookieの値 $http_<name> 指定したhttpヘッダーの値 TIPS
  47. 47. ©2022 F5 47 Proxyする際のRequest Header 書式: proxy_set_header <HTTP request ヘッダー名> <ヘッダー値> server { listen 80; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://backend-server.com; } }
  48. 48. ©2022 F5 48 Module Summary • NGINXをReverse proxyとして動作させる際にはproxy_pass directive を利用します • NGINXはHTTP以外の通信も転送することが可能です • proxy_set_header directiveを用いてHTTPヘッダーの値を設定することが 可能です
  49. 49. ©2022 F5 49 その他の参考情報
  50. 50. ©2022 F5 50 https://www.nginx.co.jp/resources/ebooks/nginx-cookbook-jp/ OʼREILLY NGINX クックブック設定レシピ集(日本語版)
  51. 51. ©2022 F5 51 NGINXドキュメント/コンテンツ https://nginx.co.jp/ NGINX日本語サイト https://nginx.org/en/docs/ https://nginx.org/en/docs/dirindex.html NGINX OSS / Directive / Variable etc. (各種マニュアル)
  52. 52. ©2022 F5 52 お問合せフォーム https://www.nginx.co.jp/contact-sales/ • 製品に関するお問い合わせ • 購入に関するお問い合わせ • 構成・設計に関するご相談 など お気軽にお問い合わせください
  53. 53. ©2022 F5 53 https://www.nginx.co.jp/free-trial-request/ https://www.nginx.co.jp/free-trial-request-nginx-ingress-controller/ NGINX Plus, NGINX App Protect 無料トライアル NGINX Plusは、オールインワン型のソフトウェアロードバランサ、コンテンツ キャッシュ、Webサーバ、APIゲートウェイ、マイクロサービスプロキシです。 NGINX App Protectは、業界トップクラスのF5の高度なWAFテクノロジーをNGINX Plusに搭載し最新のアプリケーションセキュリティを提供します。 この2つの技術の融合により、最新の分散型環境におけるWeb/モバイルアプリケー ションの拡張性と保護が実現します。 NGINX Ingress Controller with NGINX App Protect 無料トライアル NGINX Plusで実現するNGINX Ingress Controllerは、軽量で、Kubernetesアプリ ケーションに最適な高度な機能を搭載するオールインワンソフトウェアです。 無料のNGINX Service Meshとも統合することが可能で、単一の構成でnorth-south とeast-westの両方のトラフィックを管理できます。高性能な機能で、本番環境で利 用するKubernetesに最適なアプリケーションデリバリを提供します。 NGINX Plus無料トライアル NGINX Ingress Controller 無料トライアル 無料トライアル
  54. 54. ©2022 F5 54 【次回Webinarご案内】 NGINX基本セミナー(セキュリティ編) https://www.nginx.co.jp/resources/webinars/nginx_101_security 日時:2月28日(火)14時~15時 主な内容: ・NGINXのセキュリティ機能について ・NGINX Rate Limitの紹介&設定 ・JWT validation (OAuth, OIDC) ・WAFの紹介&設定 ご登録&詳細は、NGINXのWebサイトをご覧ください! www.nginx.co.jp

×