Nginx PHP-FPM别名路径

我真的放弃了。我有nginx + PHP-FPM,只是想为路径别名。 期望的:

https://example.com/api/v1.0/-> /my/folder/v1.0 /

我尝试过别名:

server {
    server_name mysite.com;
    index index.php;

    location /api/v1.0/ {
        index index.php;
        alias /my/folder/v1.0/;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass php:9000;
            fastcgi_param SCRIPT_FILENAME $request_filename;
        }
    }
}

不。日志报告nginx正在尝试访问:

/etc/nginx/html/api/v1.0

所以我改变了根:

server {
    server_name mysite.com;
    root /my/folder/v1.0/;
    index index.php;

    location /api/v1.0/ {
        index index.php;
        alias /my/folder/v1.0/;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

}

不。现在别名被忽略,nginx尝试访问:

/my/folder/v1.0/api/v1.0

我没主意了,你能帮我吗?

YOZA007 回答:Nginx PHP-FPM别名路径

好的,我能够在本地复制并修复它。 这就是我最终得到的:

        # where the actual API is
        root   /1int/code/test/nginx; 

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            try_files $uri = 404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        # This basically drops /api/1.0 prefix from the URL
        location ^~ /api/1.0 {
                rewrite ^/api/1.0/(.*)$ /$1 last;
        }

使用此配置,当我访问/api/1.0/api.php时,它将获取<root>/api.php

本文链接:https://www.f2er.com/3102109.html

大家都在问