英文:
How to run a Go http server with nginx
问题
我有一个用Go语言编写的简单HTTP服务器。
在开发环境中,它运行良好,但是在生产环境中,当这个服务器需要同时处理100个请求时,我需要一个像nginx这样的合适的Web服务器。
我该如何将它放在nginx后面?
英文:
I have a simple HTTP server written in Go.
In development It works fine but for production, where this server has to handle 100 requests at a time I need a proper web server like nginx.
How can I put it behind nginx?
答案1
得分: 15
我猜你需要一个简单的反向代理配置。
假设你的Go HTTP服务器监听在 http://example.com:8080
上:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://example.com:8080;
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 X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
英文:
I'm guessing you need a simple reverse proxy config.
Lets say your go http server is listening on http://example.com:8080
:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://example.com:8080;
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 X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论