displayabc
V2EX  ›  PHP

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

  •  
  •   displayabc · May 12, 2016 · 6689 views
    This topic created in 3860 days ago, the information mentioned may be changed or developed.

    这种方式的配置可以使用 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;
            }
    }
    

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

    Supplement 1  ·  May 12, 2016
    昨天搞了一天,第二种方法不行,今天居然又可以了。。。
    2 replies  •  2016-05-12 22:56:32 +08:00
    zhengkai
    zhengkai
    May 12, 2016❤️1
    1
    无责任建议尝试一下 error_page 403 404 /index.php;

    写在 location {} 之外
    ryd994
    ryd994
    May 12, 2016❤️1
    2
    全部由 index.php 处理么?
    加上
    fastcgi_param SCRIPT_FILENAME /full/path/to/index.php;
    或者直接全局 rewrite 到 /index.php
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1889 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 07:16 · PVG 15:16 · LAX 23:16 · JFK 02:16
    ♥ Do have faith in what you're doing.