Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a Go http server with nginx

Tags:

nginx

go

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?

like image 611
Ritesh Soni Avatar asked Dec 05 '22 15:12

Ritesh Soni


1 Answers

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 "";
    }
}
like image 157
Farhad Farahi Avatar answered Dec 26 '22 11:12

Farhad Farahi