Topic on Project:Support desk

New MediaWiki - All domain traffic is redirected to wiki; subdomain setup possible too?

2
Ribrob2379 (talkcontribs)

Hi guys, first time posting cause it's my first time setting up mediawiki on my server. I'm using nginx and I installed mediawiki under /var/www/html/w/. I setup short urls and it's working but it's routing all my traffic that goes to edhel.online to edhel.online/wiki/Main_Page.

The first thing I would like to do is have my main website, preferably I'll setup a wordpress at edhel.online and have the mediawiki at edhel.online/w/ or at wiki.edhel.online. Is there a way to do this while maintaining short urls or does the wiki need to be my landing page?


I originally had it installed in a mediawiki/ folder instead of w/ but I couldn't get wiki.edhel.online to work.


Mediawiki: 1.34.0

PHP: 7.4

Databse: MySql/MariaDB


/etc/nginx/sites-availale/default:


server {

        listen 80;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html index.php;

        server_name wiki.edhel.online;

#       return 301 https://$host$request_uri;

#       location / {

#               try_files $uri $uri/ =404;

#       }

#       location ~ \.php$ {

#         fastcgi_pass unix:/run/php/php7.4-fpm.sock;

#         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

#         include fastcgi_params;

#         include snippets/fastcgi-php.conf;

#        }

}

server {

        root /var/www/html;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name wiki.edhel.online; # managed by Certbot

        # Location for wiki's entry points

        location ~ ^/w/(index|load|api|thumb|opensearch_desc)\.php$ {

                include fastcgi_params;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                fastcgi_pass unix:/run/php/php7.4-fpm.sock; # or whatever port your PHP-FPM list$

        }

        # Images

        location /w/images {

                # Separate location for images/ so .php execution won't apply

        }

        location /w/images/deleted {

                # Deny access to deleted images folder

                deny all;

        }

        # MediaWiki assets (usually images)

        location ~ ^/w/resources/(assets|lib|src) {

                try_files $uri 404;

                add_header Cache-Control "public";

                expires 7d;

        }

        # Assets, scripts and styles from skins and extensions

        location ~ ^/w/(skins|extensions)/.+\.(css|js|gif|jpg|jpeg|png|svg|wasm)$ {

                try_files $uri 404;

                add_header Cache-Control "public";

                expires 7d;

        }

        # Favicon

        location = /favicon.ico {

                alias /w/images/6/64/Favicon.ico;

                add_header Cache-Control "public";

                expires 7d;

        }

        ## Uncomment the following code if you wish to use the installer/updater

        ## installer/updater

        #location /w/mw-config/ {

        #       # Do this inside of a location so it can be negated

        #       location ~ \.php$ {

        #               include /etc/nginx/fastcgi_params;

        #               fastcgi_param SCRIPT_FILENAME $document_root/w/mw-config/$fastcgi_script$

        #               fastcgi_pass unix:/run/php/php7.4-fpm.sock; # or whatever port your PHP-$

        #       }

        #}

        # Handling for the article path (pretty URLs)

        location /wiki/ {

                rewrite ^/wiki/(?<pagename>.*)$ /w/index.php;

        }

        # Allow robots.txt in case you have one

        location = /robots.txt {

        }

        # Explicit access to the root website, redirect to main page (adapt as needed)

        location = / {

                return 301 /wiki/Main_Page;

        }

       # Every other entry point will be disallowed.

        # Add specific rules for other entry points/images as needed above this

        location / {

                return 404;

        }

        listen [::]:443 ssl ipv6only=on; # managed by Certbot

        listen 443 ssl; # managed by Certbot

        ssl_certificate /etc/letsencrypt/live/edhel.online/fullchain.pem; # managed by Certbot

        ssl_certificate_key /etc/letsencrypt/live/edhel.online/privkey.pem; # managed by Certbot

        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {

    if ($host = www.edhel.online) {

        return 301 https://$host$request_uri;

    } # managed by Certbot

    if ($host = edhel.online) {

        return 301 https://$host$request_uri;

    } # managed by Certbot

    listen 80 ;

    listen [::]:80 ;

    server_name edhel.online;

    return 404; # managed by Certbot

}

TiltedCerebellum (talkcontribs)

If your $wgArticlePath setting in LocalSettings.php was incorrect (i.e., had /wiki/ in it) then it would explain the incorrect routing.

You should consider putting the wiki under a subdomain if you want a wordpress site under the primary domain. Running them off the same domain is not a good idea, putting mediawiki into a subdomain is a better idea.

Did you confirm your subdomain was working and displaying pages before attempting to install mediawiki under it? If not I'd do a web search on how to config a subdomain in nginx, get the subdomain working and first confirm that it's working by creating and uploading a generic index.html or index.php with something in it like "it works", and then try to view it in your browser. If you know your subdomain is first working, then you're good to go on installing mediawiki under it. But if you don't know if it's working, you don't know where the issue is.

Then after you know your subdomain is working try installing MediaWiki in the subdomain folder via the steps at Manual:Installing MediaWiki. If you don't want it nested in a /wiki/ or /w/ folder then don't leave it nested in a /wiki/ or /w/ folder. You don't have to have /wiki/ or /w/ in the file path at all. To remove it, you could via ftp upload the contents of the MW directory into your subdomain web folder. Then your path would be like: sub.yoursite.com/Main_Page instead of sub.yoursite.com/w/Main_Page. If you were extracting from command line, you could have used the --strip-componets command to strip the extra folder off and just extract the contents to the web folder of your subdomain.

tar xvzf mediawiki-1.34.2.tar.gz --strip-components 1

Then you'd have to make sure that your $wgArticlePath is correctly set. Like one of the following:

# If mediawiki files are NOT nested into a folder in your web directory:
$wgArticlePath = "/$1";

# If mediawiki files are nested into a /w/ folder in your web directory:
$wgArticlePath = "/w/$1";

# If mediawiki files are nested into a /wiki/ folder in your web directory:
$wgArticlePath = '/wiki/$1';

Though the documentation states you can't use /wiki/ with short URLs. I personally don't like nesting MW into a subfolder at all and I like having MW in its own subdomain so there can be no errors with working with files and directories on the main site and accidentally copying over a necessary MW file or folder.

Reply to "New MediaWiki - All domain traffic is redirected to wiki; subdomain setup possible too?"