【问题标题】:Nginx web-dav 409 Conflict CRUD php APINginx web-dav 409 冲突 CRUD php API
【发布时间】:2013-07-12 08:36:57
【问题描述】:

尝试为 fastcgi 的代理 HTTP CRUD 请求配置 nginx

nginx 配置:

server {
    listen   80;
    server_name api.example.dev;

    dav_methods  PUT DELETE;

    dav_access group:rw all:r;
    create_full_put_path on;

    index index_dev.php;
    set $root_path '/var/www/api/public';
    root $root_path;
    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index_dev.php?_url=/$1;
    }

    location ~ \.php {
        fastcgi_pass unix:/var/run/php-fpm.api.sock;
        fastcgi_index /index_dev.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HOST $host;
        fastcgi_param DESTINATION $http_destination;
        fastcgi_param OVERWRITE $http_overwrite;
        fastcgi_param APPLICATION_ENV dev;
    }
}

在 PHP 方面,我有 phalcon php 框架。 Witch 可以很好地处理简单的 GET/POST 请求。框架中的路由器可以处理 PUT、DELETE 方法。但是当我尝试使用上面的配置进行简单的 PUT 方法请求时,nginx 会返回 409 冲突错误。

我找不到任何关于这种情况的建议以及如何将 web_dav 方法从 nginx 传递给 php。

谢谢。

【问题讨论】:

    标签: php nginx crud


    【解决方案1】:

    这个答案是在普通 nginx WebDav 的上下文中,但也可能对您的 PHP 情况有用。我发现如果您尝试指定目标父文件夹而不是包含文件名的完整目标,您将得到 409。示例:

    设置:

    $ echo "test" >> ~/test.txt
    $ cat ~/test.txt
    test
    

    不好的测试:

    $ curl -X PUT -d `cat ~/test.txt` http://localhost:8080/
    <html>
    <head><title>409 Conflict</title></head>
    <body bgcolor="white">
    <center><h1>409 Conflict</h1></center>
    <hr><center>nginx/1.5.0</center>
    </body>
    </html>
    

    很好的测试:

    $ curl -X PUT -d `cat ~/test.txt` http://localhost:8080/test.txt
    $ curl -X GET http://localhost:8080/test.txt
    test
    $
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-13
      相关资源
      最近更新 更多