nginx, php-fpm 및 docker에서는 심볼릭 링크가 작동하지 않습니다.

nginx, php-fpm 및 docker에서는 심볼릭 링크가 작동하지 않습니다.

docker를 사용하여 로컬에서 WordPress 사이트를 실행하고 있으며 플러그인에서 심볼릭 링크인 style.css 파일에 GET 요청을 보내지만 작동하지 않고 응답합니다.404 not found

GET URI가 정확하고 심볼릭 링크 대신 하드 링크 경로를 사용할 때 작동하기 때문에 WordPress에 문제가 있다고 생각하지 않습니다.

따라서 문제는 nginx, docker 또는 nginx의 php-fpm 구성일 수 있습니다.

지금까지 stackexchange 사이트에서 몇 가지 아이디어를 찾았지만 성공하지 못했습니다.

  • disable_symlinks off;http, 서버, 위치( /위치 및 ~ \.php$위치) 의 세 가지 컨텍스트에서 nginx 설정에 명시적으로 추가합니다.
  • autoindex on;nginx, 서버 및 모든 위치 컨텍스트 추가
  • $document_rootnginx를 $realpath_root다음과 같이 변경합니다.
    • fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
  • 다음 두 줄을 추가하세요.
    • fastcgi_param DOCUMENT_ROOT $realpath_root;
    • fastcgi_param PATH_TRANSLATED $realpath_root$fastcgi_script_name;
  • 하드 링크 및 심볼릭 링크 위치에 있는 파일 및 폴더에 대한 읽기 및 실행 권한 부여
  • 파일 및 폴더의 소유자를 유효한 하드 링크와 동일한 소유자로 변경합니다(내 nginx 및 wordpress docker는 두 개의 컨테이너에 있습니다)

또 무엇을 해야할지 모르겠어요?

필요하다:

WordPress GET 요청 실패(코드, 요청 및 헤더):

  • wp_enqueue_style('my_style', plugins_url('style.css', __FILE__));
  • https://localhost/wp-content/plugins/my_plugin/style.css
  • 제목:
GET https://localhost/wp-content/plugins/my_plugin/style.css?ver=6.0.3
Status 404 Not Found
Version HTTP/1.1
Transferred 294 B (146 B size)
Referrer Policy strict-origin-when-cross-origin

유효한 WordPress GET 요청(하드 링크)(코드, 요청 및 헤더):

  • wp_enqueue_style('my_style', plugins_url( 'test_plugin/style.css', dirname(__FILE__) ));
  • https://localhost/wp-content/plugins/test_plugin/style.css
  • 제목:
GET https://localhost/wp-content/plugins/test_plugin/style.css?ver=6.0.3
Status 200 OK
Version HTTP/1.1
Transferred 548 B (318 B size)
Referrer Policy strict-origin-when-cross-origin

건축학:

                                 /
drwxr-xr-x  www-data:www-data    | home/
drwxr-xr-x  www-data:www-data    | | www-data
drwxr-xr-x  www-data:www-data    | | | my_plugin/
-rwxr-xr-x  www-data:www-data    | | | | index.php
-rwxr-xr-x  www-data:www-data    | | | | style.css
drwxr-xr-x  root:root            | var/
drwxr-xr-x  root:root            | | www/
drwxr-xr-x  www-data:www-data    | | | html/
drwxr-xr-x  www-data:www-data    | | | | wp-content/
drwxr-xr-x  www-data:www-data    | | | | | plugins/
lrwxrwxrwx  www-data:www-data    | | | | | | my_plugin/ -> /home/www-data/my_plugin
drwxr-xr-x  www-data:www-data    | | | | | | test_plugin/
-rwxr-xr-x  www-data:www-data    | | | | | | | style.css

답변1

나는 해결책을 찾았고 그것은 내 입장에서 매우 어리석은 실수였습니다.

하드 링크가 포함된 볼륨을 Nginx-Container에 제공하는 것을 잊었습니다! 따라서 Nginx 컨테이너에는 심볼릭 링크가 가리키는 하드 링크가 존재하지 않습니다.

관련 정보