Wikimedia index.php

1. Caddy version (3):

a. System environment:

docker-compose

b. Command:

docker-compose start caddy

c. Service/unit/compose file:

caddy:
    image: caddy
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - /root/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
      - /root/caddy/ssl:/data
      - /root/website:/srv
    environment:
      ACME_AGREE: 'true'
 mediawiki:
    image: mediawiki
    restart: always
    ports:
      - 8080:80
    links:
      - database
    volumes:
      - /var/www/html/images
      - ./LocalSettings.php:/var/www/html/LocalSettings.php

d. My complete Caddyfile or JSON config:

wiki.website.com {
  encode gzip
  reverse_proxy http://mediawiki
}

3. The problem I’m having:

i setup a wikimedia instance and caddy is kinda managing all the traffic/forwarding, etc - the thing is that the current configuration (i guess it’s the default one)
uses sth like: www.wiki.example.com/index.php/article_name and i’d like to get it to sth like www.wiki.example.com/wiki/article_name and according to the websites it’s done by redirecting
the website showed some examples for apache or nginx but i have no clue how to get the redirects working in caddy

RewriteEngine On
RewriteRule ^/?mediawiki/wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/mediawiki*$ %{DOCUMENT_ROOT}/w/index.php [L]*

4. Error messages and/or full log output:

5. What I already tried:

I tried to convert it but i have legit no clue how
It would be really nice if you can help me to convert it!

6. Links to relevant resources:

You no longer need this in Caddy v2, since the mere act of using Caddy is enough to agree to the ACME terms of use.

So when you run mediawiki like that with the default container, it’s actually running apache inside of the mediawiki container, and you’re proxying to that.

The mediawiki docker image Docker Hub also has an fpm variant which is basically a variant bundled with php-fpm and no server, so you could use nginx or Caddy to serve PHP that way. This is more complex though, so if you’re not sure what you’re doing, just sticking with the apache variant is good enough.

What you’ll want to do is add an .htaccess file with those rewrite rules as recommended by the sites you found. Here’s another I found:

Basically just make a /var/www/html/.htaccess volume mount with those contents and you should be good to go.

Okay yeah so i’m new to all of this haha.

So i created a file in the local directory with the following contents:

# Enable the rewrite engine
RewriteEngine On

# Short url for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

# Redirect to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

This is how i copied the file to the directory:

docker cp docker-compose_mediawiki_1:/var/www/html/.htaccess .htaccess

My compose looks like this now:

 volumes:
      - /var/www/html/images
      - ./LocalSettings.php:/var/www/html/LocalSettings.php
      - ./.htaccess:/var/www/html/.htaccess

The LocalSettings:

$wgScriptPath = "/w";
$wgArticlePath = "/wiki/$1";

And if i exec into that container I get the following:

.          CODE_OF_CONDUCT.md  FAQ      LocalSettings.php   SECURITY  autoload.php   composer.local.json-sample  images        index.php    load.php     opensearch_desc.php  skins      thumb_handler.php
..         COPYING             HISTORY  README.md           UPGRADE   cache          docs                        img_auth.php  jsduck.json  maintenance  resources            tests      vendor
.htaccess  CREDITS             INSTALL  RELEASE-NOTES-1.35  api.php   composer.json  extensions                  includes      languages    mw-config    rest.php             thumb.php

so the file is there but wiki.example.com/w/article doesn’t work… i get a 404 not found

any idea?

Sorry, I’m not sure why that wouldn’t be working; it’s ultimately not a Caddy issue at this point.

This topic was automatically closed after 30 days. New replies are no longer allowed.