내용으로 건너뛰기
권남
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
추적:
nginx:location
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== nginx location 설정 ====== * [[http://wiki.nginx.org/HttpCoreModule#location|nginx HttpCoreModule#location]] ===== alias와 root의 차이===== alias 는 특정 URL이 서빙할 파일 경로를 변경하는 역할을 한다. root와는 역할이 다르다. <code> location /images/something/ { alias /var/www/something/; } </code> 이 상태에서 ''http://example.com/images/something/somepath/myfile.png''의 실제 파일상 경로는 ''/var/www/something/sompath/myfile.png''가 된다. **중간에 location에 기술된 ''/images/something''은 경로를 구성할 때 빠진다.** 반면에 ''root /var/www/something'' 으로 구성했다면 실제 파일상 경로는 ''/var/www/something**/images/something**/somepath/myfile.png''가 된다. ===== 특정 파일 확장자에 대해 Header 추가하기 등의 작업하기 ===== ''$uri'' 변수로 파일 확장자를 확인할 수 있다. ''$uri''는 쿼리 파라미터는 모두 제거한 파일까지의 경로이다. <code> location / { if ($uri ~ ^(.+)\.(eot|ttf|woff)$) { add_header Access-Control-Allow-Origin *; } } </code> 웹폰트에 대해 ''Access-Control-Allow-Origin *'' 헤더를 추가하였다. ===== URL 중간에 정규표현식 있고, 특정 파일로 무조건 보내기 ===== <code> location ~* ^/some/([0-9a-zA-Z\-_]+)/test { rewrite .* /somefile.html; } location ~ /somefile.html { root /var/www/html; } </code> ===== POST redirect ===== <code> location ~* ^/some/test { return 302 /somefile.html; } location ~ /somefile.html { root /var/www/html; } </code> ===== Directory Listing 디렉토리 목록 ===== [[http://nginxlibrary.com/enable-directory-listing/|Enable directory listing]] <code> location /somedir { autoindex on; } </code> ===== internal ===== [[http://wiki.nginx.org/HttpCoreModule#internal|internal]]은 특정 location이 nginx 내부 요청에서만 유효하고 외부 요청에서는 404로 응답하도록 한다. 에러 페이지 등에 사용하면 좋다. <code> error_page 404 /404.html; location /404.html { internal; } </code> 내부 요청은 다음과 같은 것들을 의미한다. * ''error_page''로 인해 발생한 요청 * ''ngx_http_ssi_module'' 모듈의 ''include virtual'' 명령에 의한 요청 * ''ngx_http_rewrite_module''의 ''rewrite'' 명령에 의해 변경된 요청 ===== 참조 ===== * [[https://ohgyun.com/480|꿀벌개발일지 :: Nginx HTTP Server - 4. HTTP 환경설정]] location 설정 패턴에 대한 설명이 자세함.
nginx/location.txt
· 마지막으로 수정됨: 2019/06/26 21:24 저자
kwon37xi
문서 도구
문서 보기
이전 판
역링크
맨 위로