My docker compose looks like this:
version: '3.2'
services:
mediawiki:
image: mediawiki:lts
nginx:
image: nginx:stable-alpine
depends_on:
- mediawiki
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- 80:80
#...
Where mediawiki is a docker container that runs on port 80 in docker and does not appear to have a way to change the port number.
I’m trying to expose mediwiki
through ngninx and the nginx config looks like this:
events {
}
http {
server {
listen 80;
location / {
client_max_body_size 2M;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
proxy_pass http://mediawiki:80;
}
}
}
Since both nginx and mediawiki is running at port 80, I can’t set portmap mediwiki 80:80
.
I’ve tried mapping it to another port under mediawiki such as 7001:80
and in nginx config replace http://mediawiki:80
with http://mediawiki:7001
but this produces bad gateway error when loading the site url at port 80.
How might I fix this?
2
Answers
Change the service port for media wiki to 8080, like
8080:80
and
Change the nginx port to 7001 inside the local nginx.conf and
proxy_pass http://mediawiki:8080;
So, nginx will run on port 7001 and mediawiki on 80.
Then access the app at http://mediawiki:80
Let’s have a look at
reverse proxy
in which case I use.This should be your
wiki.conf
contents:And add a
Dockerfile
in the directory where yourdocker-compose
file is:And keep your
nginx.conf
as default values, or change some values on your own but do not add any directives to servewiki
.You can replace
THE_DOMAIN_NAME_OF_YOUR_MEDIAWIKI
wit the actual domain name. Like if you havemedia.com
and yourwiki
wants to be accessible atwiki.media.com
.Now you can run
docker-compose up -d --build
and see the result.