【问题标题】:Docker Nginx Proxy Pass Game ServerDocker Nginx 代理通行证游戏服务器
【发布时间】:2020-05-05 07:38:08
【问题描述】:

我正在尝试设置一个 Nginx docker 容器来运行我的个人网站以及在数字海洋水滴上运行我的游戏服务器。我希望example.com 是个人网站,gmod.example.com 是游戏服务器。个人网站运行良好,我能够获得一个示例节点服务器作为游戏服务器配置的调试尝试,但游戏服务器无法正常工作。我不确定我的配置有什么问题。

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

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
}

gmod.example.com.conf:

upstream gmod {
        server gmod:27015;
}

server {
        listen 27015;
        listen [::]:27015;
        server_name gmod.example.com www.gmod.example.com;

        access_log /etc/nginx/logs/gmod.access;
        error_log /etc/nginx/logs/gmod.error;

        location / {
                proxy_pass http://gmod;
        }
}

游戏服务器的 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}

使用当前设置,当我导航到 gmod.example.com 时,它给了我一个 404(考虑到配置,这是预期的,但最终,我希望它能够正常工作)。导航到 gmod.example.com:27015 会在浏览器中显示 502 Bad Gateway。访问日志显示没有发生任何事情,除非我点击了错误的网关。游戏客户端只是报告根本没有服务器。任何帮助将非常感激。理想情况下,答案是可扩展的,现在我只运行一台服务器,但将来我想要多种不同类型的运行。

在数字海洋中,我有 example.comtest.example.comgmod.example.com 的 A 记录(以及每个带有 www. 前缀的记录)。它们也都指向液滴。

【问题讨论】:

    标签: docker nginx server digital-ocean


    【解决方案1】:

    我认为您需要更改配置,因为您尝试通过 HTTP Web 协议与游戏服务器进行通信,而您实际需要的是使用 UDP/TCP 进行通信。

    这是使用ngx_stream_core_module 完成的,查看更多here

    另外,仅供参考,如果您使用的是 Nginx 预构建安装,则无需执行任何操作,只需 在http {}之外的nginx.conf文件中添加stream {}

    nginx.conf

    http {
        #web stuff here e.g. Website config
    }
    
    
    stream {        
        server {
            listen 27015;    
            proxy_pass gmod;
        }
    
        upstream gmod {
            server 127.0.0.1:27015;
        }  
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      • 2020-08-02
      • 2018-04-10
      • 1970-01-01
      • 2019-05-19
      • 1970-01-01
      相关资源
      最近更新 更多