nginx 配置 proxy_timeout 报错?

图片.png

上面的 nginx 的配置的语法有什么问题,报错:nginx: [emerg] "proxy_timeout" directive is not allowed here in /etc/nginx/conf.d/default.conf:32
nginx: configuration file /etc/nginx/nginx.conf test failed

http {
    upstream backend {
        server www.baidu.com;
        server www.baidu.com;
        server www.baidu.com;
    }

    server {
        listen 80;
        server_name example.com;
        proxy_timeout 600s;
        location / {
            proxy_pass http://backend;
            proxy_set_header Host $host;
        }
    }
}

还是不行,还有错误,即便把 proxy_timeout 移动到 server 还是报错


连 nginx 官方的都报错

图片.png

http {
    server {
        listen 127.0.0.1:12345;
        proxy_pass 127.0.0.1:8080;
    }

    server {
        listen 12345;
        proxy_connect_timeout 1s;
        proxy_timeout 1m;
        proxy_pass example.com:12345;
    }

    server {
        listen 53 udp reuseport;
        proxy_timeout 20s;
        proxy_pass dns.example.com:53;
    }

    server {
        listen [::1]:12345;
        proxy_pass unix:/tmp/stream.socket;
    }
}
╰─➤  sudo nginx -t                                              
nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/nginx.conf:4
nginx: configuration file /etc/nginx/nginx.conf test failed

我知道了,HTTP 没有 proxy_timeout
http://nginx.org/en/docs/http/ngx_http_proxy_module.html

只有 stream 有 proxy_timeout :http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html

阅读 4.5k
2 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏