Nginx阻止文件上传到静态页面:405 Not Allowed

时间:2014-08-26 13:11:10

标签: file-upload nginx upload php

我的Nginx服务器出现问题。我安装了一台新服务器,并认为我安装了与旧服务器相同的安装。但是,从那以后,我无法将文件上传到静态页面。我在index.php中有一个上传函数。当我显式调用index.php时它仍然有效,但是当我只调用/时,它给出了405错误。

我在互联网上看到了很多讨论,其中一切都归结为nginx不允许POST请求静态文件。但是,我的安装接受对静态文件的POST请求,但没有文件上载。澄清一下,这是我目前的情况:

+----------------------+-------------+------------------+
|                      | Common POST | With file upload |
+----------------------+-------------+------------------+
| Request to /         | Allowed     | Allowed          |
| Request to index.php | Allowed     | 405 Not Allowed  |
+----------------------+-------------+------------------+

它可能没有添加任何东西,但为了完整起见:我也在这台服务器上运行WordPress网站,并且因为迁移服务器我无法上传新媒体。

日志文件(/var/log/nginx/error.log/var/log/php5-fpm.log/var/log/syslog)不提供任何信息。后来,我也启用了FastCGI池的日志记录,并且在访问日志中,没有对静态页面的POST请求的记录。所以nginx必须在它们到达FastCGI之前阻止它们。

相关的PHP ini设置:

enable_post_data_reading    On
file_uploads                On
max_file_uploads            20
upload_max_filesize        20M
upload_tmp_dir        no value

如何让它再次运作?


其他信息

我的旧服务器和新服务器之间存在一些差异(可能更多,但我不知道):

  • 在nginx之前,我不得不使用fastcgi_pass 127.0.0.1:9000; - 现在,这已不再适用了,但我正在使用fastcgi_pass unix:/var/run/php5-fpm.sock;。我不确定为什么会这样或者是否重要
  • 我从源代码构建了nginx。以下是不同的安装,首先是旧安装:

       
    $ nginx -V
    nginx version: nginx/1.4.6 (Ubuntu)
    built by gcc 4.8.2 (Ubuntu 4.8.2-16ubuntu6)
    TLS SNI support enabled
    configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.4.6/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.4.6/debian/modules/nginx-dav-ext-module --add-module=/build/buildd/nginx-1.4.6/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.4.6/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.4.6/debian/modules/ngx_http_substitutions_filter_module
    

    新的:

       
    $ nginx -V
    nginx version: nginx/1.6.0
    built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
    TLS SNI support enabled
    configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/home/camilstaps/nginx-modules/nginx-auth-pam --add-module=/home/camilstaps/nginx-modules/nginx-dav-ext-module --add-module=/home/camilstaps/nginx-modules/ngx_http_substitutions_filter_module --with-http_mp4_module --with-http_flv_module
    
  • 旧的PHP版本:

       
    $ php5 -v
    PHP 5.5.9-1ubuntu4.3 (cli) (built: Jul  7 2014 16:36:58)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
        with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    

    新的:

       
    $ php5 -v
    PHP 5.5.9-1ubuntu4.3 (cli) (built: Jul  7 2014 16:36:58)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    

最后,我仍然可以访问我的旧安装。因此,如果您希望查看某些文件的内容或某些命令的输出是可能的。

1 个答案:

答案 0 :(得分:1)

问题原来是我从location /块的http_mp4_module中放了指令:

location / {
    ...
    mp4;
}

显然,这会以某种方式产生冲突。

我从此块中删除了指令并将它们放在location ~ \.mp4块中。