[TIL] HTTP : The Definitive Guide "p120~p122"

시윤·2024년 3월 29일
0

[TIL] Two Pages Per Day

목록 보기
51/110
post-thumbnail

Chapter 5. Web Servers

(해석 또는 이해가 잘못된 부분이 있다면 댓글로 편하게 알려주세요.)


❤️ 원문 번역 ❤️

Step 3: Processing Requests

Once the web server has received a request, it can process the request using the method, resource, headers, and optional body.

  • 웹 서버는 요청을 받으면 메소드, 리소스, 헤더, 그리고 선택적인 본문을 가진 요청을 처리합니다.

Some methods (e.g., POST) require entity body data in the request message. Other methods (e.g., OPTIONS) allow a request body but don’t require one. A few meth- ods (e.g., GET) forbid entity body data in request messages.

  • POST와 같은 일부 메소드는 요청 메시지 안에 엔티티 본문 데이터를 필요로 합니다.

  • OPTIONS와 같은 메소드는 요청 본문이 있을 수도 있지만 반드시 필요하지는 않습니다.

  • GET과 같은 일부 메소드는 요청 메시지 안에 엔티티 본문을 포함하지 않아야 합니다.

We won’t talk about request processing here, because it’s the subject of most of the chapters in the rest of this book!

  • 우리는 여기서 요청을 처리하는 것에 대해 이야기하지 않을 것입니다. 이 책의 남은 챕터 중 대부분이 해당 주제에 관해 이야기하기 때문입니다.

Step 4: Mapping and Accessing Resources

Web servers are resource servers. They deliver precreated content, such as HTML pages or JPEG images, as well as dynamic content from resource-generating applications running on the servers.

  • 웹 서버는 리소스 서버입니다.

  • 이것은 HTML 페이지나 JPEG 이미지와 같이 사전에 생성된 콘텐츠뿐만 아니라 서버에서 동작하는 리소스 생성 응용 프로그램에 의해 생성된 동적 콘텐츠를 전송합니다.

Before the web server can deliver content to the client, it needs to identify the source of the content, by mapping the URI from the request message to the proper content or content generator on the web server.

  • 웹 서버는 클라이언트에게 콘텐츠를 전송하기 전에 콘텐츠의 소스를 식별해야 합니다.

  • 이 과정은 요청 메시지와 적절한 콘텐츠 혹은 웹 서버의 콘텐츠 생성기 사이의 URI 매핑을 통해 이루어집니다.

Docroots

Web servers support different kinds of resource mapping, but the simplest form of resource mapping uses the request URI to name a file in the web server’s filesystem. Typically, a special folder in the web server filesystem is reserved for web content. This folder is called the document root, or docroot. The web server takes the URI from the request message and appends it to the document root.

  • 웹 서버는 다양한 종류의 리소스 매핑을 제공하고 있습니다.

  • 리소스 매핑의 가장 단순한 형태는 요청 URI를 사용하여 웹 서버 파일 시스템 내의 파일을 명명하는 것입니다.

  • 일반적으로 웹 서버 파일 시스템 내부의 특수 폴더에는 웹 콘텐츠들이 저장되어 있습니다.

  • 이 폴더를 document root 혹은 docroot라고 합니다.

  • 웹 서버는 요청 메시지로부터 URI를 취하여 document root에 추가합니다.

In Figure 5-8, a request arrives for /specials/saw-blade.gif. The web server in this example has document root /usr/local/httpd/files. The web server returns the file /usr/ local/httpd/files/specials/saw-blade.gif.

  • Figure 5-8에서는 /specials/saw-blade.gif에 대한 요청이 도착합니다.

  • 해당 예시의 웹 서버는 document root로 /usr/local/httpd/files를 가지고 있습니다.

  • 이때 usr/local/httpd/files/specials/saw-blade.gif 파일을 반환합니다.

To set the document root for an Apache web server, add a DocumentRoot line to the httpd.conf configuration file:

DocumentRoot /usr/local/httpd/files
  • Apache 웹 서버에서 document root를 설정하기 위해서는 DocumentRoot 라인을 httpd.conf 구성 파일에 추가해야 합니다.

Servers are careful not to let relative URLs back up out of a docroot and expose other parts of the filesystem. For example, most mature web servers will not permit this URI to see files above the Joe’s Hardware document root:

http://www.joes-hardware.com/../
  • 서버는 Relative URL이 docroot에서 백업되고 파일 시스템의 다른 부분들을 노출되지 않도록 주의해야 합니다.

  • 예를 들어, 가장 발달된 웹 서버는 Joe's Hardware document root의 상위 파일을 열람하려 하는 해당 URI를 제한할 것입니다.

    http://www.joes-hardware.com/../

Virtually Hosted Docroots

Virtually hosted web servers host multiple web sites on the same web server, giving each site its own distinct document root on the server. A virtually hosted web server identifies the correct document root to use from the IP address or hostname in the URI or the Host header. This way, two web sites hosted on the same web server can have completely distinct content, even if the request URIs are identical.

  • 가상 호스팅된 웹 서버는 동일한 웹 서버 안에 여러 개의 웹 사이트를 향유하고 있습니다. 이때 각각의 사이트는 서버의 고유한 document root를 가지고 있습니다.

  • 가상 호스팅된 웹 서버는 URI 혹은 Host 헤더에 존재하는 IP 주소나 호스트명을 통해 올바른 document root를 식별합니다.

  • 이 방식으로 동일한 웹 서버에 호스팅된 두 웹 사이트의 요청 URI가 동일하더라도 완전히 다른 콘텐츠를 보유할 수 있습니다.

In Figure 5-9, the server hosts two sites: www.joes-hardware.com and www.marys-antiques.com. The server can distinguish the web sites using the HTTP Host header, or from distinct IP addresses.

  • When request A arrives, the server fetches the file for /docs/joe/index.html.
  • When request B arrives, the server fetches the file for /docs/mary/index.html.
  • Figure 5-9에서 서버는 두 개의 사이트(www.joes-hardware.com, www.marys-antiques.com)를 향유하고 있습니다.

  • 서버는 HTTP Host 헤더나 서로 다른 IP 주소를 사용하여 웹 사이트를 구별할 수 있습니다.

  • 요청 A가 도착하면, 서버는 /docs/joe/index.html로부터 파일을 가져옵니다.

  • 요청 B가 도착하면, 서버는 /docs/mary/index.html로부터 파일을 가져옵니다.

Configuring virtually hosted docroots is simple for most web servers. For the popular Apache web server, you need to configure a VirtualHost block for each virtual web site, and include the DocumentRoot for each virtual server (Example 5-3).

Example 5-3. Apache web server virtual host docroot configuration

<VirtualHost www.joes-hardware.com>
  ServerName www.joes-hardware.com
  DocumentRoot /docs/joe
  TransferLog /logs/joe.access_log
  ErrorLog /logs/joe.error_log
</VirtualHost>
<VirtualHost www.marys-antiques.com>
  ServerName www.marys-antiques.com
  DocumentRoot /docs/mary
  TransferLog /logs/mary.access_log
  ErrorLog /logs/mary.error_log
</VirtualHost>
    ...
  • 대부분의 웹 서버에서 가상 호스팅된 docroots를 간단하게 구성할 수 있습니다.

  • 가장 널리 사용되는 Apache 웹 서버의 경우 각각의 가상 웹 사이트에 대해 VirtualHost 블록을 구성한 후, 각각의 블록(가상 서버)에 DocumentRoot를 포함해야 합니다. (Example 5-3)

Look forward to “Virtual Hosting” in Chapter 18 for much more detail about virtual hosting.

  • 가상 호스팅에 대한 보다 자세한 내용은 Chapter 18의"Virtual Hosting"을 참조하기 바랍니다.

User Home Directory Docroots

Another common use of docroots gives people private web sites on a web server. A typical convention maps URIs whose paths begin with a slash and tilde (/~) followed by a username to a private document root for that user. The private docroot is often the folder called public_html inside that user’s home directory, but it can be configured differently (Figure 5-10).

  • 또다른 Docroot의 보편적인 사용법은 사람들에게 웹 서버의 개인 웹 사이트를 제공하는 것입니다.

  • 일반적으로 유저명 뒤에 나타나는 슬래시와 틸드(/~)로 시작되는 경로를 포함한 URI를 사용자의 개인 document root에 매핑합니다.

  • 개인 docroot는 보통 사용자의 home 디렉토리 내부의 public_html이라고 불리는 폴더입니다. 하지만 이것은 다르게 구성될 수도 있습니다. (Figure 5-10)


🧡 요약 정리 🧡

What Web Servers Do

Step 1: Accepting Client Connections

https://velog.io/@dvlp-sy/TIL-HTTP-The-Definitive-Guide-p113-p116

Step 2: Receiving Request Messages

https://velog.io/@dvlp-sy/TIL-HTTP-The-Definitive-Guide-p116-p119

Step 3: Processing Requests

  • 요청 처리
  • 추후 자세히 이야기할 내용이라 자세히 언급 X

Step 4: Mapping and Accessing Resources

  • 웹 서버 = 리소스 서버 (정적 콘텐츠 + 동적 콘텐츠 전송)
  • 서버가 클라이언트에게 콘텐츠를 전송하기 전에 콘텐츠의 소스를 식별하는 과정
  • 콘텐츠 소스 식별을 위해 다양한 종류의 리소스 매핑 활용

Resource Mapping

* Document Root(Docroot) : 웹 서버의 파일 시스템에서 웹 콘텐츠들이 저장되는 폴더

  1. Virtually Hosted Docroots : 동일한 웹 서버 안에 여러 개의 웹 사이트가 고유한 document root 보유 -> Host 헤더나 IP 주소로 Docroot 식별
  2. User Home Directory Docroots : home 디렉토리 내에 개인 document root 보유 -> URI의 /~{username} 부분을 통해 식별

💛 감상 💛

  • Virtualization의 개념은 참 여기저기서 많이 사용되는 것 같습니다. 컴퓨터 메모리나 클라우드컴퓨팅을 배울 때도 잘 와닿지 않는 이 용어를 이해하느라 애를 먹었던 기억이 있습니다. 그런데 Virtualization은 그냥 뻥튀기입니다. Virtual Memory는 마치 메모리의 용량이 큰 것처럼 뻥튀기하기 위해 사용하고, Virtual Machine은 마치 많은 컴퓨터가 있는 것처럼 뻥튀기하기 위해 사용하고, Docker는 마치 여러 개의 OS 커널을 사용하고 있는 것처럼 뻥튀기하기 위해 사용합니다. Docroot도 마찬가지입니다. 실제로는 웹 서버의 파일 시스템을 나누어 사용하는 것뿐이지만 사용자 입장에서는 여러 개의 서버가 존재하는 것처럼 보이게 합니다.

  • 웹 서버의 파일 시스템에 리소스가 어떤 식으로 저장되어 있고, 어떤 매커니즘으로 이것에 접근하는지는 지금껏 알지 못했습니다. 오늘도 새로운 지식을 얻어갑니다...!

profile
맑은 눈의 다람쥐

0개의 댓글

관련 채용 정보