By macstation
Hello, I have a domain example.com, and I want that to be my regular website. However, I want to run a gameserver for some friends and I hosted on gmod.example.com, 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 gmod.example.com:27015 listening, but even if I go to that address, the game still won’t connect.
docker-compose.yml:
version: '3'
services:
reverseproxy:
container_name: reverseproxy
hostname: reverseproxy
image: nginx
ports:
- 80:80
- 443:443
- 27015:27015
volumes:
- ~/test/nginx/:/etc/nginx/
- ~/test/sslcerts/:/etc/letsencrypt/
- ~/test/websites:/var/www/
- /etc/ssl/certs/dhparam.pem:/etc/ssl/certs/dhparam.pem
depends_on:
- gmod
gmod:
container_name: gmod
hostname: gmod
build:
context: ~/test/game_servers/gmod
gmod.example.com.conf:
upstream gmod {
server gmod:27015;
}
server {
listen 27015;
listen [::]:27015;
server_name example.com www.example.com;
location / {
proxy_pass http://gmod;
}
}
example.com.conf:
server {
listen 443 ssl http2; #Certbot
listen [::]:443 ssl http2 ipv6only=on; #Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; #Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; #Certbot
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
#include /etc/nginx/snippets/header.conf;
#include /etc/nginx/snippets/ssl.conf;
server_name example.com www.example.com;
root /var/www/example.com;
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 = www.example.com) {
return 301 https://$host$request_uri;
} #certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} #certbot
server_name example.com www.example.com;
return 404; # certbot
}
Game Dockerfile:
FROM cm2network/steamcmd:root
ENV STEAMAPPID 4020
ENV STEAMAPPDIR /home/steam/gmod
ENV MAP gm_flatgrass
ENV GAMEMODE sandbox
# Run Steamcmd and install Gmod
RUN set -x \
&& "${STEAMCMDDIR}/steamcmd.sh" \
+login anonymous \
+force_install_dir ${STEAMAPPDIR} \
+app_update ${STEAMAPPID} validate \
+quit
USER steam
WORKDIR $STEAMAPPDIR
VOLUME $STEAMAPPDIR
# Set the entrypoint:
# 1) Update the server
# 2) Run the server
ENTRYPOINT ${STEAMCMDDIR}/steamcmd.sh \
+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 gmod.example.com:27015, 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.
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!
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
Let me know how it goes! Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.