하위 도메인에서 루트 폴더가 다른 여러 위치로 nginx 구성 간단한 설정이 있습니다 … server

하위 도메인의 루트 URL과 하위 도메인의 디렉토리를 서버의 두 개의 다른 폴더에 제공하려고합니다. 여기 내가 가지고 있고 작동하지 않는 간단한 설정이 있습니다 …

server {

    index index.html index.htm;
    server_name test.example.com;

    location / {
            root /web/test.example.com/www;
    }

    location /static {
            root /web/test.example.com/static;
    }
}

이 예제에서는 test.example.com/인덱스 파일을/web/test.example.com/www

과에가는 것은 test.example.com/static에서 인덱스 파일을 가져올 것/web/test.example.com/static



답변

다음에 alias지시문 을 사용해야합니다 location /static.

server {

  index index.html;
  server_name test.example.com;

  root /web/test.example.com/www;

  location /static/ {
    alias /web/test.example.com/static/;
  }

}

의 nginx 위키는 내가 할 수있는 것보다 루트 및 별칭 더 나은 사이의 차이를 설명합니다 :

처음에는 루트 지시문과 비슷하지만 문서 루트는 변경되지 않으며 요청에 사용 된 파일 시스템 경로 만 변경됩니다. 요청의 위치 부분이 요청 Nginx 문제에서 삭제됩니다.

참고 그 rootalias는 다르게 처리 슬래시를 후행.


답변

위치 지시 시스템은

시작하는 모든 요청 /static과 데이터 가 전달되는 것처럼/var/www/static

따라서 간단한 방법은 마지막 폴더를 전체 경로에서 분리합니다.

전체 경로 : /var/www/static

마지막 경로 : /static 및 첫 번째 경로 :/var/www

location <lastPath> {
    root <FirstPath>;
}

실수 한 것과 솔루션이 무엇인지 봅시다

실수 :

location /static {
    root /web/test.example.com/static;
}

귀하의 솔루션 :

location /static {
    root /web/test.example.com;
}


답변

server {

    index index.html index.htm;
    server_name test.example.com;

    location / {
        root /web/test.example.com/www;
    }

    location /static {
        root /web/test.example.com;
    }
}

http://nginx.org/r/root


답변