0

I have a Dockerized Wordpress instance. I am just testing things out and have it running on a site.

I have correctly mapped my running docker container to nginx, but the static files are not mapped. For example, instead of going to site.com folders, it goes to: http://app/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.3.2 which is not a valid URL due to app.

What am I doing wrong?

Here is my very simple nginx.conf:

upstream app {
    server 127.0.0.1:8000;
}
server {
    listen 80;
    server_name site.com;
        location / {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://app;
        }
}

Here is my docker-compose:

version: "3.2"

services:

  wordpress:
    depends_on:
      - mysql

    image: wordpress:latest
    volumes:
      - wordpress:/var/www/html
      - ./wp-config.php:/var/www/html/wp-config.php
      - ./themes:/var/www/html/wp-content/themes
    ports:
      - "8000:80"
    restart: always
    env_file:
      - wordpress.env

  mysql:
    image: mysql:5.7
    restart: unless-stopped
    env_file:
      - wordpress.env
    volumes:
      - mysql:/var/www/html

volumes:
  wordpress:
  mysql:

ViaTech
  • 2,143
  • 1
  • 16
  • 51
  • please, where stay this file nginx.conf ? i do not see in docker file composer, I am with same problem =( you could share your full docker file composer? – jonathasborges1 Jul 16 '22 at 01:31
  • @jonathasborges1 that is my full `docker-compose` for this attempt. I was using nginx as a local installation on my my server, which in most instances is held here: `/etc/nginx/` if you want an example that uses nginx in a docker-container, where you can define the config files in your code, check a different version I finished using here: https://stackoverflow.com/q/72807333/8382028 doing this I mapped my local default conf file to the docker container...however if you are having the exact issue I bring up here, my answer should fix your issue, notice `proxy_pass http://127.0.0.1:8000;`? – ViaTech Jul 17 '22 at 12:17

1 Answers1

2

Well, it appeared I didn't have the correct headers set for my proxy. Changing the config as it is below worked perfectly fine:

server {
    listen 80;
    server_name site.com;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;   # important line here!
        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;
    }
}

ViaTech
  • 2,143
  • 1
  • 16
  • 51