Обработка 405 при POST

Aleks Feltin aleksf at scms.fi
Mon Oct 22 23:30:11 MSD 2007


Igor Sysoev wrote:
> On Fri, Oct 19, 2007 at 02:04:27AM +0300, Aleks Feltin wrote:
>
>   
>> Доброго времени суток!
>>
>> Nginx-0.5.32 общается с php5-cgi по UNIX сокету. На днях столкнулся с 
>> проблемой - SOAP клиент POSTом генерирует структуру страницы, возвращая 
>> категории. User-Agent пользователя использует GET метод. Все бы хорошо, 
>> но вместо категорий приходит 405 - в итоге, пользователь видит пустую 
>> страницу. При чтении архивов рассылки, обнаружил, что такой POST в nginx 
>> стандартно генерирует 405 ошибку. У меня при дебаге:
>>
>> 2007/10/18 23:29:54 [debug] 1732#0: *1561 http finalize request: 405, "/?"
>> 2007/10/18 23:29:54 [debug] 1732#0: *1561 http special response: 405, "/"
>> 2007/10/18 23:29:54 [debug] 1732#0: *1561 http set discard body
>> 2007/10/18 23:29:54 [debug] 1732#0: *1561 HTTP/1.1 405 Not Allowed
>>     
>
> nginx возвращает 405 при POSTе в статику. Как статический файл может
> обработать POST ?
>
>   
>> Как workaround было предложено ее обработать, что я и пытался проделать 
>> следующим путем:
>>
>> error_page   405 = /fallback;
>>   location = /fallback {
>>   fastcgi_pass unix:/tmp/spawn-fcgi.sock;
>> }
>>
>> В access логе теперь вместо 404 200 OK, но сама страница не изменилась. 
>> У меня вопрос, на правильном ли я пути и нужно ли передать еще 
>> какие-нибудь директивы в секцию обработки?
>>
>> В Apache у меня подобных проблем не возникало, самому довольно сложно 
>> найти решение данной проблемы, посему прошу вас о помощи.
>>     
>
> Приведите полный отладочный лог сессии. Из описания не понятно, что
> должно происходить и что же, собственно, происходит.
>
>
>   
Попробую объяснить.

Изначально я привел немного неверную информацию. Вся генерация страницы 
проходит путем POST в template файлы, которые генерируют layout - index.php.

Различие в поведении работы nginx и apache можно наблюдать в access.log.

Apache:

192.168.1.100 - - [22/Oct/2007:20:25:11 +0300] "GET 
/admin/machine_ws.php?wsdl HTTP/1.1" 200 1804 "-" "PEAR HTTP_Request 
class ( http://pear.php.net/ )"
192.168.1.100 - - [22/Oct/2007:20:25:11 +0300] "POST 
/admin/machine_ws.php HTTP/1.0" 200 514 "-" "PEAR-SOAP 0.11.0-beta"

nginx:

192.168.1.100 - - [22/Oct/2007:20:27:33 +0300] GET 
/admin/machine_ws.php?wsdl HTTP/1.1 "200" 23888 "-" "PEAR HTTP_Request 
class ( http://pear.php.net/ )" "-"
192.168.1.100 - - [22/Oct/2007:20:27:33 +0300] POST / HTTP/1.0 "405" 173 
"-" "PEAR-SOAP 0.11.0-beta" "-"

В первом случае вижу контент, во втором - пустую страницу.

  server {
        listen       80;
        server_name  styx.abc.int;

        charset off;

        access_log  logs/ContentFactory.access.log  main;

        location / {
            root   /var/www/ContentFactory;
            index  index.php;
        }

        rewrite ^/get/([^/\.]+)/([^/]+)$ /get/index.php?contid=$1 last;

        client_max_body_size  16m;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            fastcgi_pass   php;
            fastcgi_index  index.php;
            fastcgi_connect_timeout 120;
            fastcgi_send_timeout 180;
            fastcgi_read_timeout 180;
            fastcgi_buffer_size 32k;
            fastcgi_buffers 4 32k;
            fastcgi_busy_buffers_size 32k;
            fastcgi_temp_file_write_size 32k;
            fastcgi_intercept_errors on;
            fastcgi_param  SCRIPT_FILENAME  
/var/www/ContentFactory$fastcgi_script_name;
            include conf/fastcgi_params;
       }
}

Из отладочного лога nginx как раз виден второй (GET) запрос в корень.

2007/10/22 22:15:28 [debug] 4522#0: *244 http fastcgi record length: 8
2007/10/22 22:15:28 [debug] 4522#0: *244 http fastcgi sent end request
2007/10/22 22:15:28 [debug] 4522#0: *244 input buf 0810D3D8 3
2007/10/22 22:15:28 [debug] 4522#0: *244 pipe write downstream: 1
2007/10/22 22:15:28 [debug] 4522#0: *244 pipe write downstream flush in
2007/10/22 22:15:28 [debug] 4522#0: *244 http output filter 
"/admin/machine_ws.php?wsdl"
2007/10/22 22:15:28 [debug] 4522#0: *244 copy filter: 
"/admin/machine_ws.php?wsdl"
2007/10/22 22:15:28 [debug] 4522#0: *244 http postpone filter 
"/admin/machine_ws.php?wsdl" 080C90A0
2007/10/22 22:15:28 [debug] 4522#0: *244 http postpone filter out 
"/admin/machine_ws.php?wsdl"
2007/10/22 22:15:28 [debug] 4522#0: *244 http chunk: 23872
2007/10/22 22:15:28 [debug] 4522#0: *244 http chunk: 3
2007/10/22 22:15:28 [debug] 4522#0: *244 write old buf t:1 f:0 080C8EA8, 
pos 080C8EA8, size: 149 file: 0, size: 0
2007/10/22 22:15:28 [debug] 4522#0: *244 write new buf t:1 f:0 00000000, 
pos 080C90F4, size: 6 file: 0, size: 0
2007/10/22 22:15:28 [debug] 4522#0: *244 write new buf t:1 f:0 08107660, 
pos 08107690, size: 23872 file: 0, size: 0
2007/10/22 22:15:28 [debug] 4522#0: *244 write new buf t:1 f:0 08107660, 
pos 0810D3D8, size: 3 file: 0, size: 0
2007/10/22 22:15:28 [debug] 4522#0: *244 write new buf t:0 f:0 00000000, 
pos 080AC309, size: 2 file: 0, size: 0
2007/10/22 22:15:28 [debug] 4522#0: *244 http write filter: l:0 f:0 s:24032
2007/10/22 22:15:28 [debug] 4522#0: *244 http write filter limit 0
2007/10/22 22:15:28 [debug] 4522#0: *244 writev: 24032
2007/10/22 22:15:28 [debug] 4522#0: *244 http write filter 00000000
2007/10/22 22:15:28 [debug] 4522#0: *244 copy filter: 0 
"/admin/machine_ws.php?wsdl"
2007/10/22 22:15:28 [debug] 4522#0: *244 pipe write downstream done
2007/10/22 22:15:28 [debug] 4522#0: *244 event timer: 14, old: 
3374767046, new: 3374767226
2007/10/22 22:15:28 [debug] 4522#0: *244 http upstream exit: 00000000
...
2007/10/22 22:15:28 [debug] 4522#0: *246 http request line: "POST / 
HTTP/1.0"
2007/10/22 22:15:28 [debug] 4522#0: *246 http uri: "/"
2007/10/22 22:15:28 [debug] 4522#0: *246 http args: ""
2007/10/22 22:15:28 [debug] 4522#0: *246 http exten: ""
2007/10/22 22:15:28 [debug] 4522#0: *246 http process request header line
2007/10/22 22:15:28 [debug] 4522#0: *246 http header: "User-Agent: 
PEAR-SOAP 0.8.0RC4-devel"
2007/10/22 22:15:28 [debug] 4522#0: *246 http header: "Host: styx.abc.int"
2007/10/22 22:15:28 [debug] 4522#0: *246 http header: "Content-Type: 
text/xml; charset=UTF-8"
2007/10/22 22:15:28 [debug] 4522#0: *246 http header: "Content-Length: 622"
2007/10/22 22:15:28 [debug] 4522#0: *246 http header: "SOAPAction: 
"http://schemas.xmlsoap.org/soap/envelope/#Machine#phonewidth""
2007/10/22 22:15:28 [debug] 4522#0: *246 http header done
2007/10/22 22:15:28 [debug] 4522#0: *246 event timer del: 13: 3374647261
2007/10/22 22:15:28 [debug] 4522#0: *246 generic phase: 0
2007/10/22 22:15:28 [debug] 4522#0: *246 http script regex: 
"^/get/([^/\.]+)/([^/]+)$"
2007/10/22 22:15:28 [debug] 4522#0: *246 find location for "/"
2007/10/22 22:15:28 [debug] 4522#0: *246 find location: "/"
2007/10/22 22:15:28 [debug] 4522#0: *246 find location: = "/50x.html"
2007/10/22 22:15:28 [debug] 4522#0: *246 find location: ~ "\.php$"
2007/10/22 22:15:28 [debug] 4522#0: *246 using configuration "/"
...
2007/10/22 22:15:28 [debug] 4522#0: *246 open index 
"/var/www/ContentFactory/index.php"
2007/10/22 22:15:28 [debug] 4522#0: *246 add cleanup: 080C8878
2007/10/22 22:15:28 [debug] 4522#0: *246 open() 
"/var/www/ContentFactory/index.php" failed (2: No such file or directory)
2007/10/22 22:15:28 [debug] 4522#0: *246 http index check dir: 
"/var/www/ContentFactory"
2007/10/22 22:15:28 [debug] 4522#0: *246 content phase: 9
2007/10/22 22:15:28 [debug] 4522#0: *246 content phase: 10
2007/10/22 22:15:28 [debug] 4522#0: *246 http finalize request: 405, "/?"
2007/10/22 22:15:28 [debug] 4522#0: *246 http special response: 405, "/"
2007/10/22 22:15:28 [debug] 4522#0: *246 http set discard body
2007/10/22 22:15:28 [debug] 4522#0: *246 HTTP/1.1 405 Not Allowed

Я не могу понять, чем обусловлено такое поведение, ведь разницы в 
конфигурации никакой - один глобальный location как в Apache так и в 
Nginx. Возможно каким-то образом обработать POST и послать его в 
/admin/machine_ws.php ?





More information about the nginx-ru mailing list