Why is reverse proxy is not working with nginx?

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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Accepted Answer
setsebool httpd_can_network_connect on -P

Please follow more information

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel