无需使用 nginx GET 和 POST 反向代理我的 Flask 服务器就可以正常工作。 但在反向代理中它不起作用。
我的 nginx.conf 文件是
# nginx.conf
# HTTP server block for handling HTTP requests
`server {
listen 80;
location / {
proxy_pass http://flask:5000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Content-Type "application/json";
}
}`
我遇到的错误是 $curl -X POST -H "Content-Type: application/json" -d '{"message": "Hello from cURL!"}' http://x.x.x.x/ % 总计 % 已接收 % Xferd 平均速度 时间 时间 时间 当前 Dload 上传总花费左速度 100 184 100 153 100 31 2091 423 --:--:-- --:--:-- --:--:-- 2555
<!doctype html>
<html lang=en>
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>`