Docker中的nginx和Go(Golang)是分开的容器。Nginx配置

huangapple go评论106阅读模式
英文:

Docker nginx and Go (Golang) separate containers. Nginx configuration

问题

在我的本地主机上,我有两个容器:Nginx和Golang。我想从我的本地机器发送请求并从Go(localhost-> Nginx-> Go)获取响应。

容器是正常工作的。我可以进入Nginx容器并运行curl -v 'test:8080/path' -d "param1=value1&param2=value2",我得到了正确的响应。

但是,如果我尝试从主机机器上运行相同的请求,我得到了一个错误 - 502 Bad Gateway。如果我更改请求并运行curl -v -X POST 'test:8080/path'(相同的请求但没有数据)- 这是可以的。

我的Nginx配置如下:

server {
    listen 80;
    server_name test;

    client_max_body_size 20M;

    charset utf8;

    location / {
        proxy_pass http://go:8000;  // 这里是go - docker compose的链接
    }
}

我认为问题在于Nginx的配置。但是我对nginx不太熟悉。请帮帮我 Docker中的nginx和Go(Golang)是分开的容器。Nginx配置

英文:

On my localhost I've got Docker with 2 containers: Nginx and Golang. I want to do request from my local machine and get response from Go (localhost -> Nginx -> Go).

Containers work. I can go into Nginx container and run
curl -v 'test:8080/path' -d "param1=value1&param2=value2" and I've got correct response.

But If I try to run the same request from host machine I've got an error - 502 Bad Gateway. If I change request and run curl -v -X POST 'test:8080/path' (same request without data) - It's ok.

My Nginx config:

server {
    listen 80;
    server_name test;

    client_max_body_size 20M;

    charset utf8;

    location / {
        proxy_pass http://go:8000;  // there go - docker compose link
    }
}

I think, problem in Nginx configuration. But I'm newbie with nginx. Plz, help me Docker中的nginx和Go(Golang)是分开的容器。Nginx配置

答案1

得分: 1

抱歉,大家。我的Go程序没有返回任何内容。因此,nginx响应解释为错误请求,并返回502错误。

英文:

My fault, guys. My Go program returns nothing. So nginx interpreted empty response as bad request and return 502.

huangapple
  • 本文由 发表于 2015年10月3日 02:04:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/32913192.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定