Why is reverse proxy is not working with nginx?

July 27, 2019 95 views
Nginx Go Deployment Fedora CentOS

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?

1 Answer
httpsomkar July 29, 2019
Accepted Answer
setsebool httpd_can_network_connect on -P

Please follow more information

Have another answer? Share your knowledge.