Skip to content

Commit

Permalink
Use internal Apache rewrites (#5)
Browse files Browse the repository at this point in the history
* Rewrite internally in Apache

* Try to fix infinite redirects

* Use more generic file name

* More documentation

* Cleanup, less strict env variables

* Depend on database

* Make README match configuration options
  • Loading branch information
GAsplund authored Aug 14, 2024
1 parent 37db86f commit 5a20bfa
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ Includes a proxy that helps routing to sub-paths.

# Usage with Gamma

In order to authorize with Gamma, create a client with a redirect URL that matches `https://[URL of wiki]/wiki/index.php/Special:PluggableAuthLogin`.
In order to authorize with Gamma, create a client with a redirect URL that matches `https://[URL of wiki]/[wiki path]/Special:PluggableAuthLogin`.
Also make sure that the email scope is enabled.
If you want to make any restrictions on who can access the wiki, you can set those directly on the client.
The wiki will not do any additional checks other than login status.

# Wiki Setup

After creating a blank software stack (e.g. through Docker compose), you should be able to access the wiki through the proxy at http://localhost:4000/wiki, or directly at http://localhost:4001.
The wiki can now be initialized by navigating to http://localhost:4000/wiki/mw-config and following the instructions.
After creating a blank software stack (e.g. through Docker compose), you should be able to access the wiki through the proxy at `http://localhost:4000/[wiki path]`, or directly at `http://localhost:4001/[wiki path]`.
Note that doing the latter requires setting `ROOT_URL` to match the non-proxied version, or else all further links will incorrectly lead to the proxied version.
The wiki can now be initialized by navigating to `http://localhost:4000/[wiki path]/mw-config` and following the instructions.
Should you encounter a 404 error when clicking continue, navigate directly to the wiki setup page at http://localhost:4001/mw-config.

If there are any database-related errors after initialization, run the upgrade script: `php maintenance/update.php`.
Expand All @@ -23,12 +24,14 @@ More information about this update script can be found in MediaWiki's [documenta
> [!WARNING]
> Make sure that there exists a backup of the database before running the upgrade script.
## Upgrating from previous versions
## Upgrading from Previous Versions

If you are upgrading from version < 1.39, you will need to run the upgrade script to create new database tables used by new extensions: `php maintenance/update.php`.

## Configuration

### Environment Variables

The following environment variables can be set to configure the wiki:

| Variable | Description | Default | Example |
Expand All @@ -37,13 +40,13 @@ The following environment variables can be set to configure the wiki:
| `CLIENT_ID` | The client ID of the provider | (Required) | `123456` |
| `CLIENT_SECRET` | The client secret of the provider | (Required) | `abcdef` |
| `WIKI_NAME` | The name of the wiki | (Required) | `My Wiki` |
| `WIKI_PATH` | The root path of the wiki | (Required) | `/wiki` |
| `WIKI_PATH` | The root path of the wiki | `""` | `/wiki` |
| `ROOT_URL` | The root URL of the wiki | (Required) | `https://wiki.chalmers.it` |
| `DB_SERVER` | URL to the database | (Required) | `db` |
| `DB_NAME` | The database name to use | (Required) | `wiki` |
| `DB_USER` | Username to access database | (Required) | `wiki` |
| `DB_PASSWORD` | Password to access database | (Required) | `password` |
| `DB_PREFIX` | Prefix to be used when addressing database. | (Required) | `mw_` |
| `DB_PREFIX` | Prefix to be used when addressing database. | `mw_` | `wiki_` |
| `SECRET_KEY` | The secret key for the wiki | (Required) | `secret` |
| `UPGRADE_KEY` | The upgrade key for the wiki. Used for installs. | (Required) | `123456` |
| `ENABLE_LOCAL_LOGIN` | Enable local login for the wiki. | `false` | `false` |
Expand All @@ -52,3 +55,8 @@ The following environment variables can be set to configure the wiki:
| `WORDMARK_WIDTH` | Width of the wordmark (max 124) | `124` | `64` |
| `WORDMARK_HEIGHT` | Height of the wordmark (max 32) | `32` | `32` |
| `DEFAULT_SKIN` | Default skin to use. Is also displayed for non-logged in users | `citizen` | `vector-2022` |

### Choosing a Path

If you want to host the wiki under a subdirectory, setting the `WIKI_PATH` environment variable to the desired path will make the wiki accessible at `http://localhost:4000/[wiki path]`.
If you want to host the wiki at the root, set `WIKI_PATH` to an empty string.
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ services:
SECRET_KEY: dasdasdasd
UPGRADE_KEY: dasd
ROOT_URL: http://localhost:4000
depends_on:
- wiki-db
ports:
- 4001:80
volumes:
Expand Down
5 changes: 4 additions & 1 deletion mediawiki/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RUN git checkout 4ff9d24

# Install ParserFunctions for MediaWiki 1.39
WORKDIR /tmp
RUN curl -L https://extdist.wmflabs.org/dist/extensions/ParserFunctions-REL1_39-7fa883d.tar.gz -o ParserFunctions.tar.gz
RUN curl -L https://extdist.wmflabs.org/dist/extensions/ParserFunctions-REL1_39-1ce7bc0.tar.gz -o ParserFunctions.tar.gz
RUN tar -xzf ParserFunctions.tar.gz -C /var/www/html/extensions
WORKDIR /var/www/html

Expand All @@ -41,5 +41,8 @@ RUN git clone https://github.com/StarCitizenTools/mediawiki-skins-Citizen Citize
WORKDIR /var/www/html/skins/Citizen
RUN git checkout 9caf91a

# See https://www.mediawiki.org/wiki/Topic:Weqepsq3e8po62y1
COPY ./apache-custom-directory.conf /etc/apache2/sites-available/000-default.conf

COPY ./LocalSettings.php /var/www/html/
WORKDIR /var/www/html
13 changes: 6 additions & 7 deletions mediawiki/LocalSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
## For more information on customizing the URLs
## (like /w/index.php/Page_title to /wiki/Page_title) please see:
## https://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath = $_ENV["WIKI_PATH"];
$wgScriptPath = $_ENV["WIKI_PATH"] ?? "";

## The protocol and server name to use in fully-qualified URLs
$wgServer = $_ENV["ROOT_URL"];

## The URL path to static resources (images, scripts, etc.)
$wgResourceBasePath = $wgScriptPath;
# The base URL that is used to construct all internal links
# Normally points to the main index.php script. Can be relative or absolute
$wgArticlePath = "$wgScriptPath/$1";

$wgArticlePath = "/wiki/$1";

## The URL paths to the logo. Make sure you change this from the default,
## The URL paths to the logo. Make sure you change this from the default,
## or else you'll overwrite your logo when you upgrade!
$wgLogos = [
'icon' => "$wgScriptPath/images/logo.png",
Expand Down Expand Up @@ -72,7 +71,7 @@
$wgDBpassword = $_ENV["DB_PASSWORD"];

# MySQL specific settings
$wgDBprefix = $_ENV["DB_PREFIX"];
$wgDBprefix = $_ENV["DB_PREFIX"] ?? "mw_";

# MySQL table options to use during installation or update
$wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";
Expand Down
20 changes: 20 additions & 0 deletions mediawiki/apache-custom-directory.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Allows all resources to be accessed on its given subpath
# Resolves 404 errors when files are served at the root
LoadModule env_module modules/mod_env.so
LoadModule alias_module modules/mod_alias.so

<VirtualHost *:80>
<If "env('WIKI_PATH') != ''">
Define WIKI_ALIAS_PATH "${WIKI_PATH}"
</If>
<If "env('WIKI_PATH') == ''">
Define WIKI_ALIAS_PATH ""
</If>

Alias ${WIKI_ALIAS_PATH} /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

AllowEncodedSlashes NoDecode
</VirtualHost>
4 changes: 1 addition & 3 deletions proxy/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ http {
}

location /${WIKI_PATH} {
# Trailing slash is important, strips the location before forwarding,
# if location is /wiki, a request to /wiki/a would be forwarded to /a
proxy_pass http://wiki/;
proxy_pass http://wiki;
}
}
}

0 comments on commit 5a20bfa

Please sign in to comment.