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条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?