![Nginx 이미지 파일 이름은 정규식으로 URI를 수정하여 크기를 제거합니다.](https://rvso.com/image/697381/Nginx%20%EC%9D%B4%EB%AF%B8%EC%A7%80%20%ED%8C%8C%EC%9D%BC%20%EC%9D%B4%EB%A6%84%EC%9D%80%20%EC%A0%95%EA%B7%9C%EC%8B%9D%EC%9C%BC%EB%A1%9C%20URI%EB%A5%BC%20%EC%88%98%EC%A0%95%ED%95%98%EC%97%AC%20%ED%81%AC%EA%B8%B0%EB%A5%BC%20%EC%A0%9C%EA%B1%B0%ED%95%A9%EB%8B%88%EB%8B%A4..png)
nginx 구성에서 WordPress 이미지 이름 지정/크기 표기 규칙에 따라 필요한 이미지 크기를 찾을 수 없는 경우 원본 이미지를 반환하는 가장 좋은 방법은 무엇입니까?
따라서 /image-name-150x170.png를 찾을 수 없으면 /image-name.png를 반환하고 싶습니다. -150-170 부분은 다른 숫자일 수 있습니다. 따라서 파일 이름에서 점 앞에 대시 1-4자리 x 1-4자리를 제거하고 싶습니다.
@static_full 위치 블록 내부의 uri 코드에 대체 항목을 넣거나 다시 작성하고 싶습니다. 성능면에서 어느 것이 더 나을지 궁금합니다.
#some locations here and then
location ~* ^.+\.(png|gif|jpg|jpeg){
access_log off;
log_not_found off;
expires max;
error_page 404 = @static_full; #if not found, seek #static_ful
}
location @static_full{
#modify uri here to remove image dimensions like below
#uri = remove dash 1-4 digits x 1-4 digits before dot
#or rewrite to original name
}
location / {
try_files $uri $uri/ /index.php?$args ;
}
업데이트, 어떻게 해야 하는지 알아냈습니다. 다음은 내가하고 싶은 일을했습니다.
location @static_full{
#modify uri here to remove image dimensions like below
#uri = remove dash three digits x three digits before dot
rewrite "^(.*)(-[\d]{1,4}+x[\d]{1,4}+.)([\w]{3,4})" $1.$3 break;
}
답변1
try_files
지시문 대신 사용을 고려할 수도 있습니다 error_page
.
try_files $uri @static_full;
보다이 문서자세한 내용은.
편집 - 전체 솔루션 추가:
location ~* ^.+\.(png|gif|jpg|jpeg) {
try_files $uri @static_full;
access_log off;
log_not_found off;
expires max;
}
location @static_full {
rewrite "^(.*)(-[\d]{1,4}+x[\d]{1,4}+.)([\w]{3,4})" $1.$3 break;
}
location / {
try_files $uri $uri/ /index.php?$args ;
}