dongsha7215 2014-08-26 13:11
浏览 583
已采纳

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

I'm having a problem with my Nginx server. I installed a new server and thought I put up the same installation as on my old one. However, since then, I cannot upload files to static pages. I had an upload function in an index.php. It still works when I explicitly call index.php, but when I just call /, it gives me a 405 error.

I have seen numerous discussions on the internet where it all comes down to nginx not allowing POST requests to static files. However, my installation accepts POST requests to static files, but no file uploads. To clarify, this is my current situation:

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

It probably doesn't add anything, but for the sake of completeness: I'm running a WordPress site on this server as well, and since migrating the server I have not been able to upload new media.

The logfiles (/var/log/nginx/error.log, /var/log/php5-fpm.log, /var/log/syslog) don't give any information. Later, I enabled logging for the FastCGI pool as well, and there in the access log, there is no record of the POST requests to the static page. So nginx must block them before they get to FastCGI.

The relevant PHP ini settings:

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

How can I make it work again?


Additional information

There are some differences between my old server and the new server (maybe more, but I'm not aware):

  • In nginx, before, I had to use fastcgi_pass 127.0.0.1:9000; - now, this doesn't work anymore, but I'm using fastcgi_pass unix:/var/run/php5-fpm.sock;. I'm not sure why this is or if it matters
  • I built nginx from source. Here are the different installations, first the old one:

    $ 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
    

    And the new one:

    $ 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
    
  • The old PHP version:

    $ 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
    

    And the new one:

    $ 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
    

Lastly, I still have access to my old installation. So if you'd like to see the content of some file or the output of some command that's possible.

  • 写回答

1条回答 默认 最新

  • dsc7188 2014-08-27 20:59
    关注

    The problem turned out to be that I had put directives from the http_mp4_module in the location / block:

    location / {
        ...
        mp4;
    }
    

    Apparently, this gives a conflict somehow.

    I removed the directives from this block and put them in a location ~ \.mp4 block.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!