title: How do I fix nginx reverse proxy to a wordpress docker redirecting port for the user?
body: <p>So I have a raspberry pi web server I have been experimenting with, which runs nginx to serve multiple sites and such. I want to run wordpress in a docker container as a blog, but I am having issues configuring the nginx+docker wordpress setup correctly.</p>
  <p>Here is my docker-compose.yml:</p>
  <pre><code>version: &quot;3&quot;
  services:
    db:
      image: hypriot/rpi-mysql
      restart: always
      volumes:
        - db_data:/var/lib/mysql
      environment:
        MYSQL_ROOT_PASSWORD: password
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: &lt;password&gt;
      networks:
        - wp
  
    wordpress:
      depends_on:
        - db
      image: wordpress
      restart: always
      volumes:
        - ./:/var/www/html/wp-content
      environment:
        WORDPRESS_DB_HOST: db:3306
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: &lt;password&gt;
      ports:
        - 8082:80
      networks:
        - wp
  
  networks:
    wp:
  
  volumes:
    db_data:
  </code></pre>
  <p>Here is my current nginx .conf for example.com:</p>
  <pre><code>server {
      client_max_body_size 32M;
  
      # Listen HTTP
      listen 80;
      server_name www.example.com example.com;
  
      # Redirect HTTP to HTTPS
      return 301 https://$host$request_uri;
  
  }
  
  server {
      client_max_body_size 32M;
      
      # Listen HTTP
      listen 443 ssl;
  
      server_name example.com www.example.com;
  
      # SSL config
      ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
     
      # does not fix the issue
      port_in_redirect off;
  
      # Proxy Config
      location / {
  
          # My attempts at fixing the port issue (did not work in any combination) 
          proxy_bind $host:443;
          proxy_redirect off;
          port_in_redirect off;
          absolute_redirect off;
          proxy_set_header Location $host:443;
          proxy_set_header Host $http_host:443;
  
          proxy_set_header X-Forwarded-Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_pass http://localhost:8082/;
      
          # an extra try despite my 8082 port not being open
          proxy_redirect https://example.com:8082/ https://example.com/;
      }
  
      # testing and looking at just the /wp-login.php &quot;works&quot; but without any of the content
      location ~ \.php {
          proxy_pass http://127.0.0.1:8082;
      }
  
  }
  
  
  </code></pre>
  <p>My issue: upon visiting my <code>example.com</code> domain, I am getting redirected to <code>example.com:8082</code> and not getting any of the content and I've had a lot of issue trying to figure out a way of fixing it. I have also tried just using http on port 80 but that doesn't make a difference (unless I am on the local network, for which it gets the files locally)</p>
  <p>Is there a simple thing that I am missing from the above nginx setup?</p>
  <p>Is there a way to make the docker forward it on a different virtual port?</p>