V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
haython
V2EX  ›  PHP

Nginx+PHP-FPM 的怎么配置让它支持 RESTFul?

  •  
  •   haython · 2016-05-12 11:08:24 +08:00 · 6047 次点击
    这是一个创建于 2904 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这种方式的配置可以使用 delete , put 等方法了,但是只能访问 http://rest.website.com/,其它路径不能访问

    server {
      listen        80;
      server_name   rest.website.com;
      root          /website/public/;
      index         index.php;
      location / {
        include         fastcgi.conf;
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
      }
    }
    

    这种方式可以访问其它路径,但是不能用 delete , put 等方法,只要 nginx 认为是访问的文件,就不能使用 delete , put 等方法

    server
    {
            listen          80;
            server_name     rest.website.com ;
            index           index.php;
            root            /website/public/;
            location / {
                try_files $uri $uri/ /index.php$is_args$args;
            }
            location ~ .*\.php?$ {
                try_files $uri =404;
                fastcgi_index index.php;
                include fastcgi.conf;
                fastcgi_pass 127.0.0.1:9000;
            }
    }
    

    搜索了一大圈没找到要怎么配置

    第 1 条附言  ·  2016-05-12 11:54:33 +08:00
    昨天搞了一天,第二种方法不行,今天居然又可以了。。。
    2 条回复    2016-05-12 22:56:32 +08:00
    zhengkai
        1
    zhengkai  
       2016-05-12 11:19:10 +08:00   ❤️ 1
    无责任建议尝试一下 error_page 403 404 /index.php;

    写在 location {} 之外
    ryd994
        2
    ryd994  
       2016-05-12 22:56:32 +08:00   ❤️ 1
    全部由 index.php 处理么?
    加上
    fastcgi_param SCRIPT_FILENAME /full/path/to/index.php;
    或者直接全局 rewrite 到 /index.php
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3841 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:55 · PVG 08:55 · LAX 17:55 · JFK 20:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.