사용자 도구

사이트 도구


nginx:location

문서의 이전 판입니다!


nginx location 설정

alias와 root의 차이

alias 는 특정 URL이 서빙할 파일 경로를 변경하는 역할을 한다. root와는 역할이 다르다.

location /images/something/ {
    alias /var/www/something/;
}

이 상태에서 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는 쿼리 파라미터는 모두 제거한 파일까지의 경로이다.

location / {
  if ($uri ~ ^(.+)\.(eot|ttf|woff)$)
  {
    add_header Access-Control-Allow-Origin *;
  }
}

웹폰트에 대해 Access-Control-Allow-Origin * 헤더를 추가하였다.

URL 중간에 정규표현식 있고, 특정 파일로 무조건 보내기

location ~* ^/some/([0-9a-zA-Z\-_]+)/test {
  rewrite .* /somefile.html;
}

location ~ /somefile.html {
  root /var/www/html;
}

POST redirect

location ~* ^/some/test {
  return 302 /somefile.html;
}

location ~ /somefile.html {
  root /var/www/html;
}

Directory Listing 디렉토리 목록

Enable directory listing

location /somedir {
    autoindex on;
}
nginx/location.1390376420.txt.gz · 마지막으로 수정됨: 2014/01/22 16:40 저자 kwon37xi