2012-04-10 4 views
7
server { 
    listen  80; 
    server_name pwta; 
    root html; 

    location /test/{ 
     alias html/test/; 
     autoindex on; 
    } 
    location ~ \.php$ { 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
    } 
} 

이 구성이 작동합니다. 그러나 location /test/이 다음과 같이 바뀌면 location /testpath/ 작동하지 않습니다 (입력 파일이 지정되지 않았습니다). 별칭 지시문에 대한 설명에 기초하여 "위치"부분이 삭제되어 /testpath/info.phphtml/test/info.php이됩니다.nginx 별칭 + 위치 지시문

의견을 보내 주셔서 감사합니다.

답변

10

nginx alias

server { 
    listen  80; 
    server_name pwta; 
    index index.html index.php; 
    root html; 

    location /testpath/ { 
     alias html/test/; 
    } 
    location ~ ^/testpath/(.+\.php)$ { ### This location block was the solution 
     alias html/test/;  
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$1; 
     include fastcgi_params; 
    } 
    location ~ \.php$ { 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
    } 
+0

그 이유는 완전히 이해하지 못하고 있지만 실제로 문제를 해결합니다. 누구든지 그 중간 위치 블록에 대해 더 많은 설명을 추가 할 수 있습니까? – Brad

+0

'alias'를 추가하면'$ document_root'를 별명이 무엇이든간에 효과적으로 덮어 쓸 것입니다. '$ fastcgi_script_name'이나'$ request_filename'에는 영향을 미치지 않습니다. 새'$ document_root'를 파일 이름과 일치하는 정규식과 함께 사용하면 스크립트 파일로 해석됩니다. – Gajus

+0

요청이'/ testpath /'에있을 때 마지막 위치 블록이 아무 것도하지 않음에 유의하십시오. – Gajus

8

모두 aliasroot 지침은 최고의 절대 경로로 사용됩니다. 상대 경로를 사용할 수는 있지만 nginx를 컴파일하는 데 사용되는 prefix 구성 옵션과 관련이 있으며 일반적으로 원하는 것은 아닙니다.

nginx -V을 실행하고 --prefix= 다음에 오는 값을 찾아서 확인할 수 있습니다.

로그를보고 자신에게 증명할 경우 "해당 파일 없음"오류가 표시됩니다.

+1

'-V'는'-v'가 아니어야합니다 (대문자 여야하며, 소문자는 버전 번호 만 제공해야합니다) – Basic