Hosting Server Through Nginx Reverse proxy

Hello, I have a domain, and I want that to be my regular website. However, I want to run a gameserver for some friends and I hosted on, and I can’t seem to get that working. I’ve tried a variety of combinations of nginx config files, and I’m not sure where the issue is. Currently, my config has listening, but even if I go to that address, the game still won’t connect.


version: '3'

        container_name: reverseproxy
        hostname: reverseproxy
        image: nginx
          - 80:80
          - 443:443
          - 27015:27015
          - ~/test/nginx/:/etc/nginx/
          - ~/test/sslcerts/:/etc/letsencrypt/
          - ~/test/websites:/var/www/
          - /etc/ssl/certs/dhparam.pem:/etc/ssl/certs/dhparam.pem
          - gmod
        container_name: gmod
        hostname: gmod
            context: ~/test/game_servers/gmod

upstream gmod {
        server gmod:27015;

server {
        listen 27015;
        listen [::]:27015;

        location / {
                proxy_pass http://gmod;

server {
        listen 443 ssl http2; #Certbot
        listen [::]:443 ssl http2 ipv6only=on; #Certbot
        ssl_certificate /etc/letsencrypt/live/; #Certbot
        ssl_certificate_key /etc/letsencrypt/live/; #Certbot

        ssl_trusted_certificate /etc/letsencrypt/live/;
        #include /etc/nginx/snippets/header.conf;
        #include /etc/nginx/snippets/ssl.conf;

        root /var/www/;

        index index.html;
        location / {
                include /etc/nginx/snippets/header.conf;
                try_files $uri $uri/ =404;

        #for certbot renewal
        location ~ /.well-known/acme-challenge {
                allow all;
                root /data/letsencrypt;

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        if ($host = {
                return 301 https://$host$request_uri;
        } #certbot

        if ($host = {
                return 301 https://$host$request_uri;
        } #certbot

        return 404; # certbot

Game Dockerfile:

FROM cm2network/steamcmd:root

ENV STEAMAPPDIR /home/steam/gmod
ENV MAP gm_flatgrass

# Run Steamcmd and install Gmod
RUN set -x \
        && "${STEAMCMDDIR}/" \
                +login anonymous \
                +force_install_dir ${STEAMAPPDIR} \
                +app_update ${STEAMAPPID} validate \

USER steam



# Set the entrypoint:
# 1) Update the server
# 2) Run the server
                +login anonymous +force_install_dir ${STEAMAPPDIR} +app_update ${STEAMAPPID} +quit \
                && ${STEAMAPPDIR}/srcds_run \
                        -game garrysmod -maxplayers 16 +gamemode ${GAMEMODE} +map ${MAP}

The ports the game server uses are 27015 and 27005, both TCP and UDP. Something is clearly working because if I open a web browser and go to, I get a 502 Bad Gateway error.

For more context, though I don’t think it’s necessary for the problem: The game I’m trying to run is Garry’s mod, and I’m doing it with the SteamCMD Docker Container.

I tried using my config on a sample node application, and that worked, so I don’t know how else to do this. It’s very possible the game client is programmed weird and won’t accept subdomains (when I add the subdomain to the game client, it just reformats it to my droplet-ip:27015.

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @macstation,

I could suggest a couple of things:

  • Make sure that your game server container is actually running, if you try to visit your gmod container directly does it work?

  • Check your Nginx container logs, this should give you more information regarding the exact problem rather than the generic 502 error:

docker logs nginx_container_id
  • Make sure that the two containers are part of the same network so that they communicate to each other via their hostnames

Let me know how it goes! Regards, Bobby