openresty中配置
lua_package_path "/home/user/lua/?.lua;;";
server {
listen 80;
lua_code_cache off;
location /data/test/ {
content_by_lua_file /home/user/data/test.lua;
}
location /data/ {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
}
uwsgi启动的是一个bottle应用,里面处理POST方式的 /data/hello/
在 test.lua中 使用 ngx.location.capture('/data/hello/', { method=ngx.HTTP_POST, body="hello, world" })
在lua里面打印出返回的body 如下:
\n <!DOCTYPE HTML PUBLIC \"-\/\/IETF\/\/DTD HTML 2.0\/\/EN\">\n <html>\n <head>\n <title>Error: 405 Method Not Allowed<\/title>\n <style type=\"text\/css\">\n html {background-color: #eee; font-family: sans;}\n body {background-color: #fff; border: 1px solid #ddd;\n padding: 15px; margin: 15px;}\n pre {background-color: #eee; border: 1px solid #ddd; padding: 5px;}\n <\/style>\n <\/head>\n <body>\n <h1>Error: 405 Method Not Allowed<\/h1>\n <p>Sorry, the requested URL <tt>'http:\/\/127.0.0.1:8000\/data\/hello\/'<\/tt>\n caused an error:<\/p>\n <pre>Method not allowed.<\/pre>\n <\/body>\n <\/html>\n
而在uwsgi的log里面看到请求的是 GET /data/test/ => generated 745 bytes in 15 msecs (HTTP/1.1 405) 3 headers in 108 bytes (1 switches on core 0)
请问这是什么原因?