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:

2
  • 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? Commented Jul 16, 2022 at 1: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: 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;? Commented Jul 17, 2022 at 12:17

1 Answer 1

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;
    }
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.