英文:
Docker nginx and Go (Golang) separate containers. Nginx configuration
问题
在我的本地主机上,我有两个容器:Nginx和Golang。我想从我的本地机器发送请求并从Go(localhost-> Nginx-> Go)获取响应。
容器是正常工作的。我可以进入Nginx容器并运行curl -v 'test:8080/path' -d "param1=value1¶m2=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不太熟悉。请帮帮我
英文:
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
答案1
得分: 1
抱歉,大家。我的Go程序没有返回任何内容。因此,nginx
将空
响应解释为错误请求,并返回502错误。
英文:
My fault, guys. My Go program returns nothing. So nginx
interpreted empty
response as bad request and return 502.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论