Why is reverse proxy is not working with nginx?

Posted July 27, 2019 60.9k views

I have spun up a Fedora box, and am running a golang server at port 8080. I am trying to setup nginx reverse proxy on that application so that I can access it through port 80.

If you want to skip reading the whole question, here’s the error:

2019/07/27 05:50:46 [crit] 4186#0: *1 connect() to failed (13: Permission denied) while connecting to upstream, client: <MY IP>, server: _, request: "GET / HTTP/1.1", upstream: "", host: "<DROPLET IP>"

I have a really minimal golang app:

package main

import (

func helloWorld(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, you requested: %s\n", r.URL.Path)

func main() {
    http.HandleFunc("/", helloWorld)
    http.ListenAndServe(":8080", nil)

At this point when I run go run main.go, I can go to port 8080 and see the response (it’s 200).

I have a default nginx.conf with following modifications.

server {
    listen      80;
    server_name _;  # I have tried changing this to my droplet IP as well
    root        /usr/share/nginx/html;

    location / {

    # Followed by the default error handing

The response I’m getting back is 502 Bad Gateway.

What might be wrong?

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer
setsebool httpd_can_network_connect on -P

Please follow more information