Nginx with Code-Server

I am uploading a stack with the following compose:I am uploading a stack with the following compose:

services: 
  code-server:
    container_name: code-server
    hostname: CodeServer
    image: lscr.io/linuxserver/code-server:latest
    
    volumes:
      #bind -compartilhado
      - ${HOME_PATH}/Documentos/Repositorio/stacks/ansible/ansible/ansible_cw5:/config/workspace/ansible_cw5
      - code-server-data:/data
    
    networks:
      nginx-local:
        ipv4_address: 10.120.4.3
    
    ports:
      - 8081:8443 #mapear portas no NGINX

    #sera reiniciado auto a menos que seja parado manualmente
    restart: unless-stopped
    
    depends_on:
      - ansible

    environment:
      - PUID=1000
      - PGID=1000
      - PASSWORD=${PASS} #para GUI
      - SUDO_PASSWORD=${ROOT_PASS} #senha de privilegio
      - PROXY_DOMAIN=${DOMAIN} #criar nome no DNS
      - DEFAULT_WORKSPACE=/config/workspace #diretorio de workspace
      - TZ=${TZ}


  ansible:
    container_name: ansible-v4
    hostname: Ansible

    image: ansible:v2
    
    volumes:
      #bind - compartilhado
      - ${HOME_PATH}/Documentos/Repositorio/stacks/ansible/ansible/ansible_cw5:/ansible/ansible_cw5:ro
    
    working_dir: /ansible/ansible_cw5

    networks:
      ansible-local:
        ipv4_address: 10.120.6.2
    environment:
      - TZ=America/Campo_Grande

    #container serĂĄ sempre reiniciando sempre que parar
    restart: always
    stdin_open: true   
    tty: true 
    command: bash

  nginx_manager:
    container_name: nginx-proxy
    hostname: NGINX
    image: "jc21/nginx-proxy-manager:latest"

    volumes:
      - nginx-data:/data
      - nginx-letsencrypt:/etc/letsencrypt  # Volume necessĂĄrio para certificados SSL/TLS

    networks:
      nginx-local:
        ipv4_address: 10.120.4.2

    ports:
      - 80:80 
      - 443:443 
      - 81:81 #gerencia NGINX

    restart: unless-stopped

    depends_on:
      - code-server

    environment:
      - INITIAL_ADMIN_EMAIL=${INITIAL_ADMIN_EMAIL}
      - INITIAL_ADMIN_PASSWORD=${INITIAL_ADMIN_PASSWORD}
  


#cria volumes persistentes
volumes:
  nginx-data:
  nginx-letsencrypt:
  code-server-data:



networks:
  nginx-local:
    driver: bridge
    ipam: 
      config:
        - subnet: 10.120.4.0/23
          ip_range: 10.120.4.0/24 
          gateway: 10.120.4.1

  ansible-local:
    driver: bridge
    ipam: 
      config:
        - subnet: 10.120.6.0/23
          ip_range: 10.120.6.0/24
          gateway: 10.120.6.1

The idea is for Ansible to be accessible via the code-server, allowing configuration files to be edited through it, and for the code-server to be accessible via a local domain already set in the /etc/hosts file to resolve to the Nginx address (10.120.4.2).

The problem is that when I access the domain in the browser, the login screen loads, but after logging in, a completely blank screen is displayed, and the URL changes to http://code-server.gabriel/?folder=/config/workspace.

However, if I access the code-server using localhost:8081, I can access it normally without any issues. This seems to be some incorrect configuration in NGINX, but I haven’t been able to figure out exactly what it could be.

I’m using NGINX Proxy Manager, and here’s the only configuration I made for the host redirection:

  • Domain Names: code-server.gabriel
  • Scheme: http
  • Forward Hostname / IP: 10.120.4.3
  • Forward Port: 8443

Container logs and the developer console in the webbrowser should give you some clues. If the URL changed, the proxy must have successfully forwarded the request the container. When a blank page appears in a webbrowser, the network tab or the console tab in the developer console can show logs and error messages to see what happened.

1 Like

Both the code-server and Nginx container logs show no sign of anything going wrong

As for the browser console logs I receive the following:

We can read plain text, just copy that, no need for screenshots.

Check the developer tools network tab, maybe some script files were not loaded. That could result in a JS error.

If not, maybe the code server version is buggy and you need to pull a fresh version.

I can’t identify what is not loading correctly

I run the code-server using the same image behind Traefik: works like a charm.

I have no special configuration. I point http and wss traffic to port 8443 that’s it (and some security hardening: STS headers, XSS filter and NoSniffing).

Judging by your screenshots, you already apply the same settings to your rp configuration.

trying to find the origin of the problem I noticed that in the next line of the file “uuid.ts” there is an unrecognized property, this “bind”, I can not understand the reason I tried to change the browser and even check the version of them, all are in versions of the minimum requirement to work:

I don’t use Code Server and JavaScript errors could be explained better by code server developer or users, but I found this in the documentation

https://coder.com/docs/code-server/FAQ#why-do-web-views-not-work

  • Access over localhost/127.0.0.1 which is always considered secure.

The error message was different, but since localhost worked, does it give anyone any new idea?

1 Like

On GitHub I found a user with a problem similar to mine, but still without solutions:

An error occurred after coder was deployed #7224