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!
What worked finally was to adding a proxy_set_header directive to my nginx.conf file:
proxy_set_header Host $http_host;
Related
i'm setting up basic authentication(credential) for loki and promtail using nginx in docker-compose. i have created htpasswd to set the password for loki and promtail andcreated seperate config file for loki and promtail and passing it through volumes.
however its not triggering authentication for loki and promtail
docker-compose.yaml
version: "2"
services:
my-nginx-service:
image: nginx
ports:
- "8098:80"
container_name: nginx
volumes:
- ./config/sites-enabled/loki:/etc/nginx/sites-enabled/loki
- ./config/conf.d/loki.conf:/etc/nginx/conf.d/loki.conf
- ./config/conf.d/loki.conf:/etc/nginx/conf.d/promtail.conf
- ./config/sites-available/default:/etc/nginx/sites-available/default
- ./config/htpasswd/.htloki:/etc/nginx/.htloki
- ./config/htpasswd/.htloki:/etc/nginx/.htpromtail
loki:
image: grafana/loki:2.0.0
container_name: loki
volumes:
- ./config/loki.yaml:/etc/config/loki.yaml
entrypoint:
- /usr/bin/loki
- -config.file=/etc/config/loki.yaml
ports:
- "3100:3100"
promtail:
image: grafana/promtail:2.0.1
container_name: promtail
user: root
volumes:
- ./log:/var/log/test
- /var/log/system.log:/var/log/root/system.log
- ./config/promtail-local-config.yaml:/etc/config/promtail-local-config.yaml
entrypoint:
- /usr/bin/promtail
- -config.file=/etc/config/promtail-local-config.yaml
ports:
- "9080:9080"
loki.conf
server {
listen 443;
location / {
auth_basic "Protected Area";
auth_basic_user_file /etc/nginx/.htloki;
proxy_pass http://loki:3100;
}
}
promtail.conf
server {
listen 442;
location / {
auth_basic "Protected Area";
auth_basic_user_file /etc/nginx/.htpromtail;
proxy_pass http://promtail:9080;
}
}
has anybody faced this issue?
Apparently, I forgot to rebuild the container images after including the .htpasswd files. Rebuilding fixed this
docker compose up --build
I'm trying to run Wordpress on Digital Ocean through Docker. Things started out well, I had it up and running in no time configured like so:
version: '3.3'
services:
wordpress:
depends_on:
- db
image: wordpress:5.5.1-php7.2-apache
container_name: wp
restart: always
volumes:
- ./www/wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: ${DB_PWD}
ports:
- 3010:80
networks:
- network
db:
image: mysql:5.7
container_name: db
restart: always
volumes:
- ./dbdata:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ${DB_PWD}
networks:
- network
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
container_name: pma
restart: always
ports:
- 3011:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: ${DB_PWD}
UPLOAD_LIMIT: 20000000
networks:
- network
networks:
network:
volumes:
db_data:
On the Digital Ocean droplet I configured Nginx as a reverse proxy:
server {
listen 80;
listen [::]:80;
server_name my.test.url;
location / {
rewrite /(.*) /$1 break;
proxy_pass http://localhost:3010;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
}
I already had my.test.url pointing to the droplet's IP.
I updated the 'siteurl' and 'home' records in the wp_options table in the database to my.test.url
This all worked well, serving the homepage if I visit my.test.url. However when I visit a deep link, like my.test.url/example I get redirected to 127.0.0.1/example where obviously nothing is running.
I don't know how to proceed; I thought setting the rewrite rule in the nginx config would do the trick but alas..
I should mention I want to run multiple sites on the Digital Ocean droplet, each serving from their own port, so 'just' serving from port 80 is not an option.
Can anyone point me in the right direction?
As it turns out, the above configuration was correct; the problem was a DNS error combined with Wordpress permalink settings that dictated a trailing slash after the post name. This caused a DNS lookup on the server that failed, resulting in the redirect to 127.0.0.1...
I'm using Wordpress + mysql + phpmyadmin with docker-compose and a reverse proxy with nginx in the host machine to send all requests to the wordpress container. After the wordpress installation I've set "site_url" and "home" option names to "http://example.com". Everything works fine when I'm browsing http://example.com/wp-admin but when I try with http://example.com it redirects me to localhost. Everything is in a remote server and I'm doing these requests from my browser and not from the server itself.
This is my nginx conf:
server {
listen 80;
listen [::]:80;
server_name example.com
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://localhost:8000;
}
}
and this is the docker-compose file:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- /home/wordpress/mysqldb:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpresspass
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- /home/wordpress/wordpress/html:/var/www/html
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpresspass
WORDPRESS_DB_NAME: wordpress
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: rootpass
If I set the option name with ServerIp:8000 the address http://example.com works but everything else redirects with the ServerIp and I'd like to use the domain name. Am I missing something with the wordpress options?
The problem was a simple syntax error. I used the command “service nginx restart” to restart and use a new nginx configuration but restart doesn’t show errors and falls back quietly to an old config. A simple ‘;’ was missing from the server name.
I have a Flask app, which runs inside a Docker container and should be exposed under a specific URL: myserver.com/mylocation. I want to use another container running Nginx as a reverse proxy to achieve the routing. I am following an awesome tutorial that got me quite far already.
My Nginx-config (the relevant part) reads:
server {
server_name myserver.com;
location /mylocation {
proxy_pass http://myapp:5000;
proxy_set_header Host $host;
rewrite ^/mylocation(.*)$ $1 break;
}
}
My docker-compose.yml reads:
version: '2'
services:
nginx:
image: nginx:latest
container_name: production_nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- 80:80
- 443:443
myapp:
build: .
image: app_image
container_name: app_container
expose:
- "5000"
Now, when I run this, I successfully get my applications' index.html from myserver.com/mylocation, but subsequent requests (the CSS, JS etc) are being fired at myserver.com without the location part (/mylocation), and so Nginx does not route them to the container and they 404. The references to CSS, JS and such are all relative, they do not (and should not) contain the server name and location.
How can I achieve this? Am I missing something in my NGinx config that would let the app know it should run at /mylocation?
As I understand a docker-compose file, using the docker-compose up command, loads the images and starts the containers. Conversely using a Dockerfile file with the docker build command creates the image only. I think I am missing something here as things aren't working as I'd like.
Following the bitnami/wordpress instructions I got an install running fine using docker-compose up d. Can then access via localhost:81
version: '2'
services:
mariadb:
image: bitnami/mariadb:latest
volumes:
- /path/to/mariadb-persistence:/bitnami/mariadb
wordpress:
image: bitnami/wordpress:latest
depends_on:
- mariadb
ports:
- '81:80'
- '443:443'
volumes:
- ./wordpress-persistence:/bitnami/wordpress
- ./apache-persistence:/bitnami/apache
- ./php-persistence:/bitnami/php
Because I want to be able to access this as domain.com.dev, I looked at implementing nginx-proxy. Following the instructions there, and with some inspiration from Docker nginx-proxy : proxy between containers, I came up with the following:
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
restart: always
ports:
- "88:80"
volumes:
- "/var/run/docker.sock:/tmp/docker.sock:ro"
mariadb:
image: bitnami/mariadb:latest
volumes:
- //c/websites/domain_com/mariadb-persistence:/bitnami/mariadb
domain.com.dev:
image: bitnami/wordpress:latest
depends_on:
- mariadb
ports:
- '81:80'
environment:
- VIRTUAL_HOST=domain.com.dev
volumes:
- //c/websites/domain_com/wordpress-persistence:/bitnami/wordpress
- //c/websites/domain_com/apache-persistence:/bitnami/apache
- //c/websites/domain_com/php-persistence:/bitnami/php
Running docker-compose up -d with this appears to complete without error. However when I access domain.com.dev in a browser, I get a default Index of / page, which suggests I somehow got partway there but not all the way. Looking at the local folders, they get created but it seems like the wordpress-persistence does not get populated, which could explain the default view in the browser.
Any thoughts on why this isn't coming up as expected? Something obvious I missed?
1) For the first approach, you need "to finish" the configuration.
If you don't have a running webserver (nginx, apache, etc.) (on port 80) - just change the port from 81 to 80:
ports:
- '80:80'
- '443:443'
and add the record "127.0.0.1 domain.com.dev" to your hosts file (/etc/hosts in linux).
P.S. you may change port from 88 to 80 at the second approach - it will work without changing hosts file
If you have a running wevserver on port 80 - then it is needed to you proxy directives at virtualhost config file. Here is an example:
server {
listen 80 default_server;
server_name _;
include expires.conf;
location / {
proxy_set_header Host $host;
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;
proxy_pass http://172.17.0.1:81;
proxy_http_version 1.1;
}
}
2) The second approach is usually used with dnsmasq configuration.
Use this and this links to get more detailed information and examples of configuration.