skip to Main Content

I have a Ubuntu server on which I installed PMPM and Golang 1.23.4.

When I go to my webaddress it only shows a gray page saying "404 page not found".

I build it on the server itself using the go build command. I then run it with PM2, but even when I run it manually with the command ./m, the pages will not be visible.

I do see my fmt.Prntln("") output that runs before the server starts, so I am sure the server starts correctly.

Also, when the server is not started, you will see a "502 Bad Gateway" page. When the server is active, you will see a "page not found" page.

My server block in NGINX:

server {

        root /var/www/website.com;
        index index.html index.htm index.nginx-debian.html;

        server_name website.com www.website.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /api/ {
        proxy_pass http://localhost:8777;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/website.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/website.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

FYI my Nuxt website is working just fine, it is just the Golang server that ain’t working properly.

When I do ps aux | grep 8777 it returns:

root      235889  0.0  0.0   7076  2176 pts/0    S+   10:43   0:00 grep --color=auto 8777

Does anyone have a clue what might be wrong.

2

Answers


  1. Chosen as BEST ANSWER

    No clue why, but on this server something is different. I had to prefix all my Go routes with /api/. So it is working now.

    In previous projects I didn't need to add that prefix.


  2. You don’t need to use nginx to check if your golang application is listening. While you are at same host as your application – check it directly.

    Attach logs from terminal where you start your golang application. It seems it’s not runing at all. So – may be it was written with errors, may be require some args or envs and so on.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search