Mediawiki静态化配置文件

文件路径:/www/server/panel/vhost/nginx/

文件名称:域名.conf

#CERT-APPLY-CHECK--START
# 用于SSL证书申请时的文件验证相关配置 -- 请勿删除
include /www/server/panel/vhost/nginx/well-known/域名.conf;
#CERT-APPLY-CHECK--END

#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
set $isRedcert 1;
if ($server_port != 443) {
    set $isRedcert 2;
}
if ( $uri ~ /\.well-known/ ) {
    set $isRedcert 1;
}
if ($isRedcert != 1) {
    rewrite ^(/.*)$ https://$host$1 permanent;

#SSL-END

#ERROR-PAGE-START  错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END

#PHP-INFO-START  PHP引用配置,可以注释或修改
#include enable-php-82.conf;
#PHP-INFO-END

#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/域名.conf;
#REWRITE-END

#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
{
    return 404;
}

#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
    allow all;
}

#禁止在证书验证目录放入敏感文件
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
    return 403;
}

location ~ ^/(images|skins|extensions)/.+\.(css|js|gif|jpg|jpeg|png|svg|wasm|ttf|woff|woff2)$
{
    expires      12h;
    access_log  /dev/null;
        error_log  /dev/null;
            #Monitor-Config-Start 网站监控报表日志发送配置
            access_log syslog:server=unix:/tmp/bt-monitor.sock,nohostname,tag=2__access monitor;
            error_log syslog:server=unix:/tmp/bt-monitor.sock,nohostname,tag=2__error;
            #Monitor-Config-End
}

location /images/deleted {
      # Deny access to deleted images folder
      deny all;
  }

server
{
listen 80;
listen 443 ssl;
listen 443 quic;
http2 on;
server_name Domain www.Domain;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/Domain-1.44;

#CERT-APPLY-CHECK--START
# 用于SSL证书申请时的文件验证相关配置 -- 请勿删除
include /www/server/panel/vhost/nginx/well-known/Domain.conf;
#CERT-APPLY-CHECK--END

#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
set $isRedcert 1;
if ($server_port != 443) {
    set $isRedcert 2;
}
if ( $uri ~ /\.well-known/ ) {
    set $isRedcert 1;
}
if ($isRedcert != 1) {
    rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
ssl_certificate    /www/server/panel/vhost/cert/Domain/fullchain.pem;
ssl_certificate_key    /www/server/panel/vhost/cert/Domain/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_tickets on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
add_header Alt-Svc 'quic=":443"; h3=":443"; h3-29=":443"; h3-27=":443";h3-25=":443"; h3-T050=":443"; h3-Q050=":443";h3-Q049=":443";h3-Q048=":443"; h3-Q046=":443"; h3-Q043=":443"';
error_page 497  https://$host$request_uri;

#SSL-END

#ERROR-PAGE-START  错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END

#PHP-INFO-START  PHP引用配置,可以注释或修改
#include enable-php-82.conf;
#PHP-INFO-END

#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/Domain.conf;
#REWRITE-END

#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
{
    return 404;
}

#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
    allow all;
}

#禁止在证书验证目录放入敏感文件
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
    return 403;
}

location ~ ^/(images|skins|extensions)/.+\.(css|js|gif|jpg|jpeg|png|svg|wasm|ttf|woff|woff2)$
{
    expires      12h;
    access_log  /dev/null;
        error_log  /dev/null;
            #Monitor-Config-Start 网站监控报表日志发送配置
            access_log syslog:server=unix:/tmp/bt-monitor.sock,nohostname,tag=2__access monitor;
            error_log syslog:server=unix:/tmp/bt-monitor.sock,nohostname,tag=2__error;
            #Monitor-Config-End
}

location /images/deleted {
      # Deny access to deleted images folder
      deny all;
  }

access_log  /www/wwwlogs/Domain.log;
error_log  /www/wwwlogs/Domain.error.log;

#Monitor-Config-Start 网站监控报表日志发送配置
access_log syslog:server=unix:/tmp/bt-monitor.sock,nohostname,tag=2__access monitor;
error_log syslog:server=unix:/tmp/bt-monitor.sock,nohostname,tag=2__error;
#Monitor-Config-End

}

Mediawiki升级

下载该软件新版本的文件。这些文件可以以来自维基媒体下载服务的压缩“tar”存档
(https://releases.wikimedia.org/mediawiki/).您也可以直接从我们的Git源代码存储库获取新文件。

用新的文件替换现有的MediaWiki文件。你应该保留LocalSettings.php文件以及“extensions”和“images”目录。

根据配置,可能还需要保留其他目录,自定义上传目录($wgUploadDirectory),已删除的文件存档,以及任何自定义皮肤。

MediaWiki需要 putenv函数

Fatal error: Uncaught Error: Call to undefined function putenv() in /www/wwwroot/www.emc.wiki/includes/Setup.php:174 Stack trace: #0 /www/wwwroot/www.emc.wiki/includes/WebStart.php(90): require_once() #1 /www/wwwroot/www.emc.wiki/index.php(44): require(‘…’) #2 {main} thrown in /www/wwwroot/www.emc.wiki/includes/Setup.php on line 174

MediaWiki添加自定义尾注 footer添加自定义链接、文字

MediaWiki网站底部,添加自定义链接、备注!

// Add a link to this page (https://www.mediawiki.org/wiki/?curid=6031)

// Add a link to this page (https://www.mediawiki.org/wiki/?curid=6031)
// test-desc is an i18n message of the text
$wgHooks['SkinAddFooterLinks'][] = function ( Skin $skin, string $key, array &$footerlinks ) {
    if ( $key === 'places' ) {
        $footerlinks['test'] = Html::element( 'a',
            [
                'href' => 'https://www.mediawiki.org/wiki/?curid=6031',
                'rel' => 'noreferrer noopener' // not required, but recommended for security reasons
            ],
        $skin->msg( 'test-desc' )->text()
        );
    };
};

//添加广州为电技术有限公司版权

// Add a link to this page (https://www.mediawiki.org/wiki/?curid=6031)
// test-desc is an i18n message of the text
$wgHooks['SkinAddFooterLinks'][] = function ( Skin $skin, string $key, array &$footerlinks ) {
    if ( $key === 'places' ) {
        $footerlinks['test'] = Html::element( 'a',
            [
                'href' => 'https://iec.wiki/',
                'rel' => 'noreferrer noopener' // not required, but recommended for security reasons
            ],
        $skin->msg( '广州为电技术有限公司 © 2024 All rights reserved.' )->text()
        );
    };
};

MediaWiki添加备案号

$wgHooks['SkinAddFooterLinks'][] = function( $skin, $key, &$footerlinks ) {
       if ( $key === 'places' ) {
               $footerlinks['ICP_Number'] = Html::rawElement( 'a', [ 'href' => 'https://beian.miit.gov.cn/' ], '粤ICP备15102220号' );
       }
};
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = function( $sk, &$tpl ) {
    $tpl->set( 'ICP_Number', Linker::makeExternalLink( 'https://beian.miit.gov.cn/', '你的备案号' ) );
    $tpl->data['footerlinks']['places'][] = 'ICP_Number';
    return true;
};

Mediawiki 怎么都不显示ico 图标

服务器伪静态规则

location ~ ^\/.+$ {
if ($request_uri ~ ^/resources) { break; }
if ($request_uri ~ ^/images) { break; }
if ($request_uri ~ ^/skins) { break; }
if ($request_uri ~ ^/index.php) { break; }
if ($request_uri ~ ^/favicon.ico){ break; }
rewrite ^/(.+)$ /index.php?title=$1 last;
}

MW伪静态MW伪静态

$wgScriptPath = "";
$wgArticlePath = "$wgScriptPath/$1";
$wgUsePathInfo = true;
$wgScriptExtension = ".php";

mediawiki 伪静态

对nginx的rewrite文件写入如下内容,如果是宝塔面板,那么如下图所示添加,并保存。

location ~ ^\/.+$ {
if ($request_uri ~ ^/resources) { break; }
if ($request_uri ~ ^/images) { break; }
if ($request_uri ~ ^/index\.php) { break; }
rewrite ^/(.+)$ /index.php?title=$1 last;
}

or

location ~ ^\/.+$ {
if ($request_uri ~ ^/resources) { break; }
if ($request_uri ~ ^/index\.php) { break; }
rewrite ^/(.+)$ /index.php?title=$1 last;
}

宝塔mediawiki 伪静态.PNG

然后再在 LocalSettings.php文件里面添加如下代码

# 伪静态
$wgScriptPath       = ""; 
$wgArticlePath = "$wgScriptPath/$1";
$wgUsePathInfo      = true; 
$wgScriptExtension  = ".php";

宝塔面板404设置

1,在根目录里面放置404页面
2、在如下配置,去掉“网站设置” -=》 配置文件 =》404前置#号

#SSL-END
#引用重定向规则,注释后配置的重定向代理将无效
include /www/server/panel/vhost/nginx/redirect/www.emc.wiki/*.conf;
    
#ERROR-PAGE-START  错误页配置,可以注释、删除或修改
error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END

MediaWiki 伪静态静态化

MediaWiki 伪静态静态化

官方的Nginx伪静态设置
https://www.mediawiki.org/wiki/Manual:Short_URL/Nginx

估计你们也难搞,建议采用宝塔面板,网站配置里面的静态化规则:

laravel5的规则

location / {  
    try_files $uri $uri/ /index.php$is_args$query_string;  
}  

MVC规则

location /{
    if (!-e $request_filename) {
       rewrite  ^(.*)$  /index.php/$1  last;
       break;
    }
}