0

I've a pretty simple setup using Wordpress and Docker, with a docker-compose.yml file:

  wordpress:
    depends_on:
      db:
        condition: service_healthy
    restart: on-failure
    image: wordpress:latest
    volumes:
      - ./backend/wordpress/wp-content:/var/www/html/wp-content
      - ./backend/wordpress/.htaccess:/var/www/html/.htaccess
    environment:
      WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST}
      WORDPRESS_DB_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX}
      WORDPRESS_CONFIG_EXTRA:
        define('WP_ALLOW_REPAIR', true );
        define('WP_HOME','${WORDPRESS_URL}:${NGINX_EXTERNAL_PORT}');
        define('WP_SITEURL','${WORDPRESS_URL}:${NGINX_EXTERNAL_PORT}');


  nginx:
    build: ./backend/nginx
    links:
      - wordpress
      - phpmyadmin
    ports: 
      - ${NGINX_EXTERNAL_PORT}:80
    volumes:
      - "./backend/nginx/nginx.conf:/etc/nginx/nginx.conf"

And this is my nginx.conf file:

upstream docker-wordpress {
    server wordpress;
}
server {
        listen 80;
        server_name admin.example.com;
        location / {
            proxy_read_timeout 3600;
            proxy_pass http://docker-wordpress;
        }
    }

Everything seems to work correctly till I try to sort my Wordpress posts by name or slug or whatever field you want, and not only when I sort but also when I try to go to a 2nd page. Instead of getting something like:

http://admin.example.com:5000/wp-admin/edit.php?post_type=artista&orderby=title&order=asc

I get my upstream name on the links, like this:

http://docker-wordpress/wp-admin/edit.php?post_type=artista&orderby=title&order=asc

As I said, everything else works fine, and after taking a look at my site configuration I see that both Wordpress URL and Site URL are:

http://admin.example.com:5000

Which I believe it's correct, any idea what could be wrong? Thanks!

4
  • Could be because wordpress is using the Host coming from the request header and that you are missing a proxy_set_header Host $host; in your location to allow that to work. docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/… Commented Aug 13, 2019 at 22:50
  • Thanks! I can't try it now but I'll try this! Makes sense Commented Aug 14, 2019 at 6:46
  • Thanks for pointing this out! Actually your solution was partially correct, as I needed to add this: proxy_set_header Host $http_host; Commented Aug 14, 2019 at 22:00
  • Feel free to make that your answer and mark your own answer as the accepted one, as it can help others in the future Commented Aug 16, 2019 at 7:36

1 Answer 1

3

What worked finally was to adding a proxy_set_header directive to my nginx.conf file:

proxy_set_header Host $http_host;

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

1 Comment

note that you can set the host to an arbitrary domain inside the location if your machine hosts multiple sites

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.