Home > Net >  Nginx and Docker Static File Issue
Nginx and Docker Static File Issue

Time:04-15

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:

CodePudding user response:

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

  • Related