본문 바로가기
Tool/Nginx

[NGINX] 3-4. Configuration-Rewrites, Redirects

by 건빵거늬 2021. 12. 18.

cf-1. 바보개발자님 블로그 글 먼저보기

https://minholee93.tistory.com/entry/Nginx-Redirect-Rewrite?category=926406 

 

[Nginx] Redirect & Rewrite

이전글에 이어서 Nginx의 configuartion에 대해 알아보도록 하겠습니다. 5. Redirect 우리가 이전글에서 사용했던 location 은 return 을 사용해 특정 uri의 request에 대한 결과값을 전달했습니다. # return loca..

minholee93.tistory.com

포스트 요약

1. Redirect란?

  1. 사용방식: location안에서 return directive으로 코딩되며 상태코드를 307로 한다.
  2. 사용이유: 파일을 return 하는 상태코드 200과 달리 새 uri를 return함.

2. Rewrite란?

  1. 사용방식: location밖에서 rewrite directive으로 코딩된다.
  2. 사용이유: redirect와 달리 내부에서 로직을 처리할 뿐 새 uri을 return하지 않음. 이는 확장자 치환기능을 포함하기 때문에 보안이 강화됨.

3. Scott Forsyth's Blog 비교표 (출처: https://blogs.iis.net/owscott/url-rewrite-vs-redirect-what-s-the-difference)

Redirect Rewrite
Client-side Server-side
Changes URL in browser address bar Doesn’t change URL in browser address bar
Supports the following redirects:
301 – Permanent
302 – Found
303 – See Other
307 - Temporary
Redirect status is non-applicable
Useful for search engine optimization by causing the search engine to update the URL. Also useful for search engines by using a friendly URL to hide a messy URL.
Example:
http://yourdomain.com to http://www.yourdomain.com in the browser
Example:
http://localtest.me/articles/how-to-win-at-chess is a friendly URL for http://localtest.me/articles.aspx?name=now-to-win-at-chess
Can redirect to the same site or an unrelated site. Generally rewrites to the same site using a relative path, although if you have the ARR module installed you can rewrite to a different site. When you rewrite to a different site, URL Rewrite functions as a reverse proxy.
The page request flow is:
  • Browser requests a page
  • Server responds with a redirect status code
  • Browser makes 2nd request to the new URL
  • Server responds to the new URL
The page request flow is:
  • Browser requests a page
  • URL Rewrite rewrites the URL and makes request (still within IIS) for the updated page
Fiddler is a great tool to see the back and forth between the browser and server. Tools like Process Monitor and native IIS tools are best for getting under the covers.

cf-2. 서버구축이야기님 블로그 글 먼저보기

https://server-talk.tistory.com/309?category=925489 

 

WEB Server - NGINX 정규표현식 알아보기 - CentOS 7

WEB Server - NGINX 정규표현식 알아보기 - CentOS 7 이번 포스팅에서는 NGINX에서 사용하게 될 정규 표현식에 대해서 알아보도록 하겠습니다. 이전 글 : 서버와 클라이언트 그리고 HTTP - https://server-talk..

server-talk.tistory.com

포스트 요약

1. URL rewrite의 활용 분야

  1. 짧은 주소로 변경
  2. 확장자 치환
  3. redirection

2. 상용하는 표현식: PCRE(Perl Compatible Regular Expression)

 

1. 307, 308 뜻

307 Temporary Redirect

The server sends this response to direct the client to get the requested resource at another URI with same method that was used in the prior request. This has the same semantics as the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request.

308 Permanent Redirect

This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request.

 

2. 실습문제

정규표현식 하나 알기
기호 설명
\w+ 한 개 이상의 알파벳 또는 숫자

*Redirect

* Rewrite

재평가란 re-evaluate를 뜻함. rewrite가 끝나면 re-evaluate를 해서 코드를 다시 읽는데 last를 하면 다시 읽지 않는다

댓글