xginx에서 특정 경로 다시 작성

xginx에서 특정 경로 다시 작성

nginx를 사용하여 특정 경로를 다시 작성하려고 합니다. nginx/php-fpm/php를 사용하여 서버를 설정했는데 제대로 작동합니다.

다음과 같은 서버 구성이 있습니다.

server {
    listen 80;

    server_name domain.com;
    root /srv/www/domain.com/public;

    location ~ ^/index.php($|/) {
        fastcgi_split_path_info ^(.+.php)(.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi_params;
    }

    location / {
       index index.php;
            try_files $uri /index.php?$args;
    }
}

그리고 이것은 작동합니다. 즉, 내가 가면 http://domain.comPHP 파일이 잘 렌더링됩니다. 그러나 지금은 특정 경로 /update/whatever/update.php?var=whatever. 이를 위해 location구성에 다음 블록을 추가했습니다( location ~ ^/index.php($|/) {블록 앞).

location ~* ^\/update/(\w+)$ {
    rewrite ^/update/(\w+)$ /update.php?browser=$1 last;
}

하지만 URL에 액세스하려고 하면 http://domain.com/update/whateverPHP에서 구문 분석된 출력을 제공하는 대신 PHP 파일을 다운로드합니다.

fastcgi또한 동일한 결과로 해당 위치 블록에 지시문을 추가해 보았습니다 . 내 구성에서 내가 무엇을 망쳤는지 말해 줄 수 있는 사람이 있나요?

답변1

이 줄은:

location ~ ^/index.php($|/) {

nginx에게 PHP 인터프리터에만 전달하도록 지시 index.php하고 다른 PHP 파일에도 적용해야 하므로 여기서는 보다 일반적인 규칙이 필요합니다.

location ~ ^/(.*).php($|/) {

관련 정보