Support » Installing WordPress » Change WordPress Container Internal Port

  • Resolved nkjuilma


    Hi there,
    I’m trying to install wordpress as a container, and route it using traefik.
    Wordpress internal port is 80, and using traefik to loadbalance to port 80 doesn’t work since traefik already uses that port.
    Can I change the internal port used within wordpress container?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz


    You’d have to explicitly include the alternate port in the URL: and configure the server to listen on that port. Probably configure the firewall to let traffic through said port as well.

    While it’s feasible to internally redirect port 80 traffic to another port, the server must still listen on port 80 and I suspect traefik will then snag such traffic before it can get to the redirect.

    Ports can also be forwarded at the router or gateway point, but then this would likely bypass traefik for all port 80 traffic. Catch-22.

    Thread Starter nkjuilma


    Hey @bcworkz , thanks for the response.

    I thought that showing the code might be more useful, this is the part about wordpress (called blc here) in my main yaml file.

        image: wordpress
        restart: unless-stopped
          - mysqlwordpress_root_password
        container_name: blc
          - com.centurylinklabs.watchtower.enable=true
          - traefik.enable=true
          - traefik.http.routers.blc.rule=Host(<code>blc.${DOMAINNAME}</code>)
          - traefik.http.routers.blc.entrypoints=websecure
          ## Middlewares
          - traefik.http.routers.blc.middlewares=chain-authelia@file   
          - traefik.http.routers.blc.service=blc@docker
          - traefik.http.routers.blc.tls=true
          - traefik.http.routers.blc.tls.certresolver=letsEncrypt
          - "8085:80"
          - PUID=${PUID}
          - PGID=${PGID}
          - TZ=${TZ}
          - WORDPRESS_DB_HOST=mysql:3306
          - WORDPRESS_DB_USER=user
          - WORDPRESS_DB_PASSWORD=/run/secrets/mysqlwordpress_root_password
          - WORDPRESS_DB_NAME=wordpress
          - ${APP_DATA_DIR}/blc:/var/www/html
          - mysql
          - internal
          - backend

    It’s the bit about the port 80 that I think creates the mess, but I don’t know how to solve it. I tried changing the loadbalancing port, but still not working.
    Any ideas, anything jumps out from the snippet?


    Moderator bcworkz


    I guess I’m not understanding why 80 cannot work for WordPress. Assuming the balancer and WordPress server each use a different LAN IP.

    Anyway, the topology I had in mind for my previous reply was probably wrong. The WordPress server could be configured to listen on nearly any port you want. It doesn’t need to be reflected in the URL. The router does need to forward traffic on the port the server is expecting. Assuming Apache server, the port to listen on is configured in its virtual host file.

    Thread Starter nkjuilma


    Quick update on how I managed, not to solve my end goal issue, which is Traefik related, but at least I found a way to change wordpress container internal port.


    exec -it container_id bash

    I checked within the container what version/type of webserver it uses, it’s apache2.
    I then created two fresh ports.conf and 000-default.conf files with the required information

    <VirtualHost *:8085>  ## changed the port here from 80 to 8085
            # The ServerName directive sets the request scheme, hostname and port that
            # the server uses to identify itself. This is used when creating
            # redirection URLs. In the context of virtual hosts, the ServerName
            # specifies what hostname must appear in the request's Host: header to
            # match this virtual host. For the default virtual host (this file) this
            # value is not decisive as it is used as a last resort host regardless.
            # However, you must set it for any further virtual host explicitly.
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
            # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
            # error, crit, alert, emerg.
            # It is also possible to configure the loglevel for particular
            # modules, e.g.
            #LogLevel info ssl:warn
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
            # For most configuration files from conf-available/, which are
            # enabled or disabled at a global level, it is possible to
            # include a line for only one particular virtual host. For example the
            # following line enables the CGI configuration for this host only
            # after it has been globally disabled with "a2disconf".
            #Include conf-available/serve-cgi-bin.conf
    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet


    Listen 8085  ## same here
    <IfModule ssl_module>
            Listen 443
    <IfModule mod_gnutls.c>
            Listen 443
    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

    which I then mapped to the folders where they’re supposed to go in the compose file.

    - ${APP_DATA_DIR}/wordpress/apache/000-default.conf:/etc/apache2/sites-available/000-default.conf
    - ${APP_DATA_DIR}/wordpress/apache/ports.conf:/etc/apache2/ports.conf

    And bim voila, it works.

    My main issue being that for some reason, traefik can’t route my desired to the wordpress container. I have loads of other containers and the config is, for all matters and purposes, the same. But somehow, I get a gateway timeout.

    Anywho, thanks for the help, I can close this thread.

    • This reply was modified 6 months, 2 weeks ago by nkjuilma.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change WordPress Container Internal Port’ is closed to new replies.