질문Q #2735
nginx location 설정 질문 드립니다.
ANO2014-06-05 20:45:00
nginx 설정중에 난관에 봉착하여 하루종일 이것만 붙잡고 있습니다. 으으으 ㅠㅠㅠ
만약 설정이 아래와 같은식으로 구성되어있다면
server {
root /usr/local/nginx/html;
location /test/ {
root /;
rewrite ^/test/(.*)$ /home/test/public_html/$1;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
http://아이피/test/a.php로 접속하는 경우 /home/test/public_html/a.php 파일을 불러주고 싶습니다.
근데 이렇게해서 php 파일을 불를 경우에는
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
여기서 $document_root 때문에인지 /usr/local/nginx/html/home/test/public_html/a.php 이런식으로 찾게되는것 같습니다.
rewrite를 사용하지 않고 location /test/ { } 내부에 location ~ \.php$ { } 를 다시 선언해주는 경우에는 제가 원하는 대로 잘 되더군요. 하지만 그렇게되면 location ~ \.php$ { } 부분이 중복되어서 영 보기 안 좋게 됩니다. 그래서 그걸 해결해보려고 끙끙이고 있습니다.
혹시 잘 아시는분은 꼭좀 답변 부탁드립니다.
참고로 위에서 제가 해결했다던 방법은 다음과 같습니다.. ^^
location /test/ {
alias /home/test/public_html/;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
아직 답변이 없습니다.