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가 된다.
$uri 변수로 파일 확장자를 확인할 수 있다. $uri는 쿼리 파라미터는 모두 제거한 파일까지의 경로이다.
location / {
if ($uri ~ ^(.+)\.(eot|ttf|woff)$)
{
add_header Access-Control-Allow-Origin *;
}
}
웹폰트에 대해 Access-Control-Allow-Origin * 헤더를 추가하였다.
location ~* ^/some/([0-9a-zA-Z\-_]+)/test {
rewrite .* /somefile.html;
}
location ~ /somefile.html {
root /var/www/html;
}
location ~* ^/some/test {
return 302 /somefile.html;
}
location ~ /somefile.html {
root /var/www/html;
}
location /somedir {
autoindex on;
}
internal은 특정 location이 nginx 내부 요청에서만 유효하고 외부 요청에서는 404로 응답하도록 한다. 에러 페이지 등에 사용하면 좋다.
error_page 404 /404.html;
location /404.html {
internal;
}
내부 요청은 다음과 같은 것들을 의미한다.
error_page로 인해 발생한 요청ngx_http_ssi_module 모듈의 include virtual 명령에 의한 요청ngx_http_rewrite_module의 rewrite 명령에 의해 변경된 요청