Re: Необходимо вернут текст на определенном location ...
Maxim Dounin
mdounin на mdounin.ru
Ср Сен 21 12:56:41 UTC 2011
Hello!
On Wed, Sep 21, 2011 at 04:09:04PM +0400, Artem S. Povaluhin wrote:
> Hello!
>
>
> On 09/21/2011 03:12 PM, Maxim Dounin wrote:
> >Hello!
> >
> >On Wed, Sep 21, 2011 at 01:19:13PM +0400, Eugene Batogov wrote:
> >
> >>Привет всем.
> >>Может ли nginx вернуть строку на определенный location.
> >>Я хочу сделать что-то наподобие этого:
> >>
> >> location /portal/v1/search/
> >>{
> >> return {"programs":[],"totalCount":0};
> >> error_page 404 502 504 = @fallback;
> >> }
> >return 200 '{"programs":[],"totalCount":0}';
> раз речь зашла, на днях обнаружил, что странно оно работает в ответ на POST.
>
> conf:
> location /dummy {
> return 200 "DONE";
> }
> curl:
> drsm at t400:~$ curl localhost/dummy -v --data "OMG"
> * About to connect() to localhost port 80 (#0)
> * Trying 127.0.0.1... connected
> * Connected to localhost (127.0.0.1) port 80 (#0)
> > POST /dummy HTTP/1.1
> > User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> > Host: localhost
> > Accept: */*
> > Content-Length: 3
> > Content-Type: application/x-www-form-urlencoded
> >
> < HTTP/1.1 200 OK
> < Server: nginx/1.0.4
> < Date: Wed, 21 Sep 2011 12:06:19 GMT
> < Content-Type: application/octet-stream
> < Content-Length: 4
> < Connection: keep-alive
> <
> * Connection #0 to host localhost left intact
> * Closing connection #0
> DONEdrsm at t400:~$
> drsm at t400:~$ tail -n2 /usr/local/nginx/logs/access.log
> 127.0.0.1 - - [21/Sep/2011:16:06:19 +0400] "POST /dummy HTTP/1.1"
> 200 4 "-" "curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"
> 127.0.0.1 - - [21/Sep/2011:16:06:19 +0400] "OMG" 400 0 "-" "-"
> drsm at t400:~$ tail -n1 /usr/local/nginx/logs/error.log
> 2011/09/21 16:06:19 [info] 1196#0: *19 client closed prematurely
> connection while reading client pipelined request line, client:
> 127.0.0.1, server: localhost, request: "OMG"
> drsm at t400:~$
Да, там ошибка, патч можно взять тут:
http://mailman.nginx.org/pipermail/nginx-devel/2011-September/001154.html
Maxim Dounin
Подробная информация о списке рассылки nginx-ru