Nginx 404页面请求方法总是GET

时间:2016-03-12 20:26:05

标签: nginx

当我发布到404页面时,nginx正在剥离帖子数据并将请求方法更改为“GET”。我该如何防止这种情况?我有nginx配置为服务php文件作为域目录的根目录中的错误404页面。我想记录发布到它的任何内容。

nginx.conf

server {
        listen 80;
        error_page 404 = /404.php;
        set $oldhost $host;
        root /var/www/www/$oldhost;
        location ~* \.(?:ico|css|js|gif|jpg|png|html|htm)$ {
            expires 3d;
            add_header Pragma public;
            add_header Cache-Control "public";
        }
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
        location / {
            index index.php index.htm index.html;
            try_files $uri $uri/ /index.php?$args;
        }
        location ~ .php$ {
            location ~ \..*/.*\.php$ {return 404;}
            expires 1d;
            add_header Pragma public;
            client_max_body_size 80m;
            add_header Cache-Control "public";
            fastcgi_pass   unix:/var/run/php5-fpm.sock;
            fastcgi_buffers 16 16k;
            fastcgi_buffer_size 32k;
            fastcgi_intercept_errors on;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

1 个答案:

答案 0 :(得分:1)

这是因为当nginx无法找到页面时,它会将用户重定向(GET)到您定义的404.php页面。

你需要做的是将它添加到try_files指令中,因此nginx会在找不到其他指令时尝试发布它,或者让你可以直接在index.php上处理404错误(如wordpress)一样)。

编辑:

 location / {
            index index.php index.htm index.html;
            try_files $uri $uri/ /index.php?$args 404.php 404.php?$args;
        }