Is there a way to specify DISCOURSE_PORT next to DISCOURSE_HOSTNAME?

The target URL is https://discourse.example.com:9443.
We use reverse proxy (nginx) on another server with this config:

Спойлер
server {
	listen 9443 ssl;
	listen [::]:9443 ssl;

	client_max_body_size 500m;

	server_name discourse.example.com;

	ssl_certificate /etc/ssl/certs/example.com.pem;
        ssl_certificate_key /etc/ssl/private/example.com.key;

	location / {
		proxy_pass http://10.250.26.133:3080/;
		proxy_set_header Host $host;
		proxy_set_header X-Real_IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
	}
}

And this containers/app.yml:

Спойлер
templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
#  - "templates/web.ssl.template.yml"
#  - "templates/web.letsencrypt.ssl.template.yml"

expose:
  - "3080:80"   # http
  - "443:443" # https

params:
  db_default_text_search_config: "pg_catalog.english"
  db_shared_buffers: "2048MB"

env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en

  UNICORN_WORKERS: 8

  DISCOURSE_HOSTNAME: discourse.example.com
  DISCOURSE_PORT: 9443 # <- this doesn't work

  #DOCKER_USE_HOSTNAME: true

  DISCOURSE_DEVELOPER_EMAILS: 'admin@example.com'

  DISCOURSE_SMTP_ADDRESS: smtp.example.com
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: example-username
  DISCOURSE_SMTP_PASSWORD: "p@ssw0rd"
  DISCOURSE_SMTP_AUTHENTICATION: login
  DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
  DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
  DISCOURSE_SMTP_DOMAIN: example.com
  DISCOURSE_NOTIFICATION_EMAIL: discourse@example.com

  LETSENCRYPT_ACCOUNT_EMAIL: me@example.com

volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-oauth2-basic.git
run:
  - exec: echo "Beginning of custom commands"
  - exec: echo "End of custom commands"

I run ./launcher rebuild app.
Then we have working url https://discourse.example.com:9443.

But

  1. I couldn’t create admin user, because Discourse redirects me to URL without 9443 port.
    I had to create admin via console (./launcher enter app and then rake admin:create)

  2. I couldn’t register any other user because the same reason.

  3. I couldn’t connect with Gitea OAuth, because Discourse generates authorize URL with wrong redirect_uri (missed 9443 port in URL)

Is there a way to specify DISCOURSE_PORT next to DISCOURSE_HOSTNAME?

You can’t access discourse on a web browser on a nonstandard port. See How to set up Discourse on a server with existing Apache sites. There is also a similar topic for nginx, but you just need the discourse part so this one should do it for you.

You also need to remove the ssl and let’s encrypt templates. Also, no need to expose 443.