###### tags: `HTTP` # HTTP通信について ## Route53、CloudFront、S3利用時のシーケンス ```mermaid sequenceDiagram ブラウザ->>Route53: www.aaaa.com(CloudFront)のIPは? Route53->>ブラウザ: IPはxxx.xxx.xxx.xxx ブラウザ->>CloudFront: GET /index.html CloudFront->>S3: GET /index.html S3->>CloudFront: index.htmlの内容 CloudFront->>ブラウザ: index.htmlの内容 ブラウザ->>ブラウザ: index.htmlの内容表示 ``` ## 通信の階層(TCP/IP, OSI参照モデル) https://www.infraexpert.com/study/tcpip.html より * ネットワーク層(L3)が、IPアドレス * トランスポート層(L4)が、TCP/UDPポート * アプリケーション層(L7)が、HTTPプロトコル ![OSI7階層](https://www.infraexpert.com/studygif/tcpip2.gif) https://ja.wikipedia.org/wiki/ルーター より ![通信の流れ](https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/TCP%E3%83%BBIP%E3%81%AE%E9%9A%8E%E5%B1%A4%E6%A7%8B%E9%80%A0%EF%BC%88%E3%83%AB%E3%83%BC%E3%82%BF%E3%83%BC%EF%BC%89.PNG/900px-TCP%E3%83%BBIP%E3%81%AE%E9%9A%8E%E5%B1%A4%E6%A7%8B%E9%80%A0%EF%BC%88%E3%83%AB%E3%83%BC%E3%82%BF%E3%83%BC%EF%BC%89.PNG) ## HTTPプロトコル ### HTTPリクエスト https://www.atmarkit.co.jp/ait/articles/1703/29/news045.html より ![](https://image.itmedia.co.jp/ait/articles/1703/29/wi-httpfig01.png) ### リクエスト/レスポンスの ヘッダ、ボディ http://www.tohoho-web.com/ex/http.htm#message より #### HTTPのサンプル ブラウザで Webページを開く際、ブラウザはサーバに下記のような要求メッセージを送信します。 ```HTTP GET / HTTP/1.1 Accept: image/gif, image/jpeg, */* Accept-Language: ja Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1;) Host: www.xxx.zzz Connection: Keep-Alive ``` これに対してサーバは下記のような応答メッセージを返します。 ```HTTP HTTP/1.1 200 OK Date: Sun, 11 Jan 2004 16:06:23 GMT Server: Apache/1.3.22 (Unix) (Red-Hat/Linux) Last-Modified: Sun, 07 Dec 2003 12:34:18 GMT ETag: "1dba6-131b-3fd31e4a" Accept-Ranges: bytes Content-Length: 4891 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html <!DOCTYPE html> <html> : </html> ``` ### nc で手動でHTTPリクエストを投げてみる #### 200ステータス:正常応答 ```shell= $ nc abehiroshi.la.coocan.jp 80 GET / HTTP/1.1 host: abehiroshi.la.coocan.jp HTTP/1.1 200 OK Date: Tue, 17 Jan 2023 12:34:08 GMT Content-Type: text/html Content-Length: 538 Connection: keep-alive Last-Modified: Thu, 27 Feb 2020 07:10:16 GMT ETag: "21a-59f8969af8600" Accept-Ranges: bytes Server: Apache <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <meta name="GENERATOR" content="JustSystems Homepage Builder Version 20.0.6.0 for Windows"> <meta http-equiv="Content-Style-Type" content="text/css"> <title>�������̃z�[���y�[�W</title> </head> <frameset cols=18,82> <frame src="menu.htm" marginheight="0" marginwidth="0" scrolling="auto" name="left"> <frame src="top.htm" marginheight="0" marginwidth="0" scrolling="auto" name="right"> <noframes> <body></body> </noframes> </frameset> </html> ``` #### 300系ステータス:リダイレクトレスポンス ```shell= $ nc yahoo.co.jp 80 GET / HTTP/1.1 host: yahoo.co.jp HTTP/1.1 301 Redirect Date: Tue, 17 Jan 2023 12:40:59 GMT Connection: keep-alive Server: ATS Cache-Control: no-store Location: https://www.yahoo.co.jp:443/ Content-Type: text/html Content-Language: en Content-Length: 1 ``` ## Apache利用時 ### シーケンス ```mermaid sequenceDiagram PC->>apache: GET /index.html apache->>disk: index.htmlの読み込み disk->>apache: index.htmlの内容 apache->>PC: index.htmlの内容 apache->>disk: ログ書込み PC->>PC: index.htmlの内容表示 ``` ### Aapcheの定義や参考リンク [コンテンツの場所](https://httpd.apache.org/docs/2.4/ja/mod/core.html#documentroot) [ログの出力定義](https://httpd.apache.org/docs/2.4/ja/mod/mod_log_config.html#customlog) [WindowsのApacheのログローテートでログを削除する方法](https://beyondjapan.com/blog/2016/09/windows-apache-logrotate/)