doukun8944 2017-04-26 13:52
浏览 878
已采纳

如何在nginx上允许PUT DELETE进行表单提交

I have a normal PHP script listening for $_SERVER["REQUEST_METHOD"] and I do the form submission using the PUT method, but I get error 405 on the nginx server.

Just want to submit a simple form using request methods.

  1 server {                                                                        
  2                                                                                 
  3  listen   80; # port 80 default                                                 
  4                                                                                 
  5  root /home/user/workspace/l; # default directory where the files will be stored and served from
  6                                                                                 
  7  index index.php index.html index.htm; # index defined to be served under directory
  8                                                                                 
  9  server_name l; #name of the virtual host or domain                  
 10                                                                                 
 11 error_log /var/log/nginx/l.error.log;                                       
 12 access_log /var/log/nginx/l.access.log;                                     
 13                                                                                 
 14                                                                                 
 15  location / {                                                                   
 16    try_files $uri $uri/ /index.html;                                            
 17  }                                                                              
 18                                                                                 
 19 # Serve PHP scripts to FastCGI server our php-fpm server listening on 127.0.0.1:9000
 20                                                                                 
 21  location ~ \.php$ {                                                            
 22   fastcgi_pass 127.0.0.1:9000;                                                  
 23   # With php5-fpm:                                                              
 24   #fastcgi_pass unix:/var/run/php5-fpm.sock;                                    
 25   fastcgi_index index.php;                                                      
 26   fastcgi_split_path_info ^(.+\.php)(/.*)$;                                     
 27   include fastcgi_params;                                                       
 28   fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;            
 29   }                                                                             
 30 }   

The request call is /index.php?groups

The initial call was:

function updateGroup(group_name, group_id) {
    values = {};
    values.name = group_name;
    values.id = group_id;
    $.ajax({
        url: '?groups',
        type: 'PUT',
        data: values,
        success: success,
        dataType: 'json'
    });
}
  • 写回答

3条回答 默认 最新

  • douna1895 2017-04-26 14:11
    关注

    nginx will only allow GET for static files. In order to allow POST/PUT, nginx has to be configured to send the request through to PHP. So, the fact that you're getting a 405 on a PUT would seem to indicate that you're requesting a static file, which would mean that your nginx configuration is not invoking PHP where you think it is. This can be tested pretty easily by requesting the same URL with GET -- if it's configured correctly, you'll get PHP output. if it's configured incorrectly, you'll get PHP source code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制