11
"static.domain.com"이미지 만 제공 할 수 있도록 nginx를 설정하려고합니다. 이것이 내가 생각해 낸 것이지만, 더 효율적으로 할 수 있다는 것을 알고 있습니다. 누군가가 .htm, .php, 디렉토리 (다른 파일이 없습니까?) 파일에 액세스하려고하면 403.html을 제공하고 싶습니다. 물론, 403.htm 및 static.htm 파일은 예외입니다.nginx - 이미지 만 제공
어떻게하면 제대로 고정시킬 수 있습니까?
server {
listen xx.xx.xx.xx:80;
server_name static.domain.com;
root /www/domain.com/httpdocs;
index static.htm;
access_log off;
error_log /dev/null crit;
error_page 403 /403.html;
# Disable access to .htaccess or any other hidden file
location ~ /\.ht {
deny all;
}
location ~* \.php {
deny all;
}
# Serve static files directly from nginx
location ~* \.(jpg|jpeg|gif|png|bmp|ico|pdf|flv|swf|exe|html|htm|txt|css|js) {
add_header Cache-Control public;
add_header Cache-Control must-revalidate;
expires 7d;
}
}
간단합니다. 그 밖의 것은 필요하지 않습니까? –
물론 내가 거기서 쓴 것을 실행하지 않았으므로 확실히 테스트해야합니다. 위치 ~ * \. (jpg | jpeg | gif | png ...)는 파이프로 구분 된 모든 유형과 일치합니다. 일치하지 않으면 "/"는 모든 것과 일치하므로 "/"와 일치합니다. –
파이어 폭스에서 액세스하는 모든 .php 파일은 사용자가 파일을 다운로드 할 수 있도록하기 때문에 (다운로드 프롬프트 표시) 좋아요. –