nginx configuration for a RESTful API

后端 未结 2 1641
走了就别回头了
走了就别回头了 2021-02-08 06:34

I am a beginner with nginx and php, so please excuse my basic question.

For a RESTful based API (nginx + php) I would need some help with nginx configuration.

H

2条回答
  •  一整个雨季
    2021-02-08 06:40

    Replace this:

    location /api/v1/ {
        try_files $uri $uri/ /apiv1.php?$args;
    }
    

    With the following inside your server block:

    rewrite ^/api/v1/([^/]+)/([^/]+)/?$ /apiv1.php?class=$1&method=$2? last;
    

    Create a php file called apiv1.php and place in the root directory of your web server with the following lines of code:

    ';
    echo $method;
    

    Test by visiting the following link in your browser:

    http://myServer/api/v1/members/getInfo
    

提交回复
热议问题