当前位置: > mediawiki知识 > 宝塔面板的mediawiki缩短域名页面重写url

宝塔面板的mediawiki缩短域名页面重写url

公子猫1年前 (2023-06-30)mediawiki知识436

首先

如果您使用的是宝塔面板,您可以通过以下步骤来修改Nginx的配置文件:

  1. 登录到宝塔面板。
  2. 在左侧菜单中,单击网站,然后选择您要修改的网站。
  3. 在网站设置页面中,单击配置文件
  4. 在弹出的窗口中,您可以编辑Nginx的配置文件。您可以下面提到的方法,在配置文件中添加相应的代码来启用URL重写。
  5. 完成编辑后,单击保存按钮,然后重启Nginx服务。

如果您在修改过程中遇到问题,您可以查看宝塔面板的官方文档或寻求宝塔面板的技术支持。

先写配置查看mediawiki官方的。

https://www.mediawiki.org/wiki/Manual:Short_URL

server {
    root /var/www/html;
    ...
    # Location for wiki's entry points
    location ~ ^/myGod/(index|load|api|thumb|opensearch_desc|rest|img_auth)\.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on
    }

    # Images
    location /myGod/images {
        # Separate location for images/ so .php execution won't apply
    }
    location /myGod/images/deleted {
        # Deny access to deleted images folder
        deny all;
    }
    # MediaWiki assets (usually images)
    location ~ ^/myGod/resources/(assets|lib|src) {
        try_files $uri 404;
        add_header Cache-Control "public";
        expires 7d;
    }
    # Assets, scripts and styles from skins and extensions
    location ~ ^/myGod/(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 /myGod/images/6/64/Favicon.ico;
        add_header Cache-Control "public";
        expires 7d;
    }

    # License and credits files
    location ~ ^/myGod/(COPYING|CREDITS)$ {
        default_type text/plain;
    }

    ## Uncomment the following code if you wish to use the installer/updater
    ## installer/updater
    #location /myGod/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$fastcgi_script_name;
    #        fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on
    #    }
    #}

    # Handling for Mediawiki REST API, see [[mw:API:REST_API]]
    location /myGod/rest.php/ {
        try_files $uri $uri/ /myGod/rest.php?$query_string;
    }

    ## Uncomment the following code for handling image authentication
    ## Also add "deny all;" in the location for /w/images above
    #location /myGod/img_auth.php/ {
    #    try_files $uri $uri/ /myGod/img_auth.php?$query_string;
    #}

    # Handling for the article path (pretty URLs)
    location /wiki/ {
        rewrite ^/wiki/(?<pagename>.*)$ /myGod/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/首页;
    }
    ...
}

我们只需要里面的注意!

要修改下面的不多请注意检查!
下面的是mediawiki安装在“域名.com/myGod/”也就是域名的二级目录就只需要修改就需要把myGod修改成你的二级目录名字。
如果是直接安在一级目录把/myGod/修改为一条“/”就行了。

还有就是下面63行的/wiki/使用了/wiki/在浏览器渲染就是https://域名.com/wiki/首页。

还有一些其他操作比如https://自定义.域名.com/wiki/首页
可以设置自定义这几个字这里的二级域名。这里没有写。

location ~ ^/myGod/(index|load|api|thumb|opensearch_desc|rest|img_auth)\.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on
    }

    # Images
    location /myGod/images {
        # Separate location for images/ so .php execution won't apply
    }
    location /myGod/images/deleted {
        # Deny access to deleted images folder
        deny all;
    }
    # MediaWiki assets (usually images)
    location ~ ^/myGod/resources/(assets|lib|src) {
        try_files $uri 404;
        add_header Cache-Control "public";
        expires 7d;
    }
    # Assets, scripts and styles from skins and extensions
    location ~ ^/myGod/(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 /myGod/images/6/64/Favicon.ico;
        add_header Cache-Control "public";
        expires 7d;
    }

    # License and credits files
    location ~ ^/myGod/(COPYING|CREDITS)$ {
        default_type text/plain;
    }

    ## Uncomment the following code if you wish to use the installer/updater
    ## installer/updater
    #location /myGod/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$fastcgi_script_name;
    #        fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on
    #    }
    #}

    # Handling for Mediawiki REST API, see [[mw:API:REST_API]]
    location /myGod/rest.php/ {
        try_files $uri $uri/ /myGod/rest.php?$query_string;
    }

    ## Uncomment the following code for handling image authentication
    ## Also add "deny all;" in the location for /w/images above
    #location /myGod/img_auth.php/ {
    #    try_files $uri $uri/ /myGod/img_auth.php?$query_string;
    #}

    # Handling for the article path (pretty URLs)
    location /wiki/ {
        rewrite ^/wiki/(?<pagename>.*)$ /myGod/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/首页;
    }

等等还有哦!

注意!还要修改配置!

准备两个东西:fastcgi_params和fastcgi_pass。
来修改上面里面的下面代码。

    #        include /etc/nginx/fastcgi_params;
    #        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #        fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on

fastcgi_params在宝塔nginx的conf文件夹里,路径为/www/server/nginx/conf/fastcgi_params。

mediawiki官网给的nginx安装在/etc/下。

宝塔Nginx和PHP-FPM的进程通信方式是UNIX Domain Socket,因此fastcgi_pass不能用官网给的IP:端口,需要改成unix:sock形式。打开宝塔面板 - 软件商店 - PHP设置 - FPM配置文件,可以看到PHP-FPM在监听/tmp/php-cgi-80.sock,fastcgi_pass就是他。

一定有修改端口不然必出问题!


没改fastcgi_pass,把官网给的127.0.0.1:9000填上去,mediawiki里的.js和.css页面打不开。

推荐一个小工具虽然我不用。。。。
https://shorturls.redwerks.org/

个人修改并且正在使用的代码可以做为参考。

#    location ~ \.php$ {
    #        include /www/server/nginx/conf/fastcgi_params;
    #        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #        fastcgi_pass 127.0.0.1:0666; # or whatever port your PHP-FPM listens on
    #    }
    #}

在mediawiki网站的LocalSettings.php添加

$wgScriptPath = "";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

然后你发现正常了,吗?
没有!
文件:XXXX.jpg通通被保护了全部404吓死你!

在把网页这些 注释/删除 就好了,主要是不舍得删除配置(一开始是看不懂的问题)的问题,这个主要是宝塔的默认安全配置问题导致有特别后缀被识别就无法加载了

#    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
#   {
#       expires      30d;
#       error_log /dev/null;
#        access_log /dev/null;
#   }
#
#   location ~ .*\.(js|css)?$
#   {
#      expires      12h;
#      error_log /dev/null;
#      access_log /dev/null;
# }

到这里还不能解决就没办法了,你去求那些大佬吧。

转载需要注明来源。

标签: mediawiki

相关文章

给你的mediawiki(公民皮肤)添加一个背景

给你的mediawiki(公民皮肤)添加一个背景

注意这个教程是全站的如果想个别页面可以使用单独页面加载javascript的方法 首先注意新版本大概率是要添加到全站的css因为新的mediawiki(本站目前1.39+)对于css有更多安全要求。...

mediawiki修复使用图片预览无法加载问题

mediawiki修复使用图片预览无法加载问题

一般情况下不正常情况下解决办法来了把站点升级成https就好了。可能是部分浏览器不能正常加载https和http混合站点导致的。注意不止部署ssl还要修改LocalSettings.php配置...