# Problems with mediawiki behind nginx / apache (redirects to wrong url)

**URL:** <https://www.ruby-forum.com/t/problems-with-mediawiki-behind-nginx-apache-redirects-to-wrong-url/211710>\
**Category:** NGINX\
**Created:** [September 11, 2011, 8:14pm UTC](https://www.ruby-forum.com/t/problems-with-mediawiki-behind-nginx-apache-redirects-to-wrong-url/211710 "2011-09-11T20:14:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 11, 2011, 8:14pm UTC](https://www.ruby-forum.com/t/problems-with-mediawiki-behind-nginx-apache-redirects-to-wrong-url/211710/1 "2011-09-11T20:14:30Z")

</div>

Hi,

I’m having a little trouble to get Mediawiki working in my nginx setup.

The problem is very probably the configuration of Mediawiki, but the  
Help pages about Mediawiki don’t mention nginx.  
So I thought I ask here.

My Problem:

- I setup nginx with https such, that it handles all files, except php  
files, which fill be proxied to apache/mod\_php at port 8081

- I installed a new Mediawiki

- the installation via the web worked fine and was confirmed  
with a success message

- then I moved config/LocalSedttings.php to the wiki directory

Now I access https:/servername/wiki2/  
and get redirected to [http://servername:8081/wiki2/index.php/Main\_Page](http://servername:8081/wiki2/index.php/Main_Page)

Below my nginx configuration:

# ============== nginx configuration ========

server {  
listen 443 ssl;  
ssl\_session\_timeout 10m;  
ssl\_session\_cache shared:SSL:10m;

```
location ~ \.(php)$ {
    include proxy.conf;
    proxy_pass http://127.0.0.1:8081;
}

# nginx shall serve all files except the php ones
location / {
    root /my/doc/root;
    index index.html index.htm index.php;
}

```

# ==================== proxy.conf ==============

proxy\_redirect off;

proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;

client\_max\_body\_size 10m;  
client\_body\_buffer\_size 128k;

proxy\_connect\_timeout 90;  
proxy\_send\_timeout 90;  
proxy\_read\_timeout 90;

proxy\_buffer\_size 4k;  
proxy\_buffers 4 32k;  
proxy\_busy\_buffers\_size 64k;  
proxy\_temp\_file\_write\_size 64k;

Thanks in advance for any pointers.

---

<div class="post-metadata">

**Author:** ![Gelonida\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/65b543/32.png) [@Gelonida\_N](https://www.ruby-forum.com/u/Gelonida_N)\
**Post date:** [September 11, 2011, 8:46pm UTC](https://www.ruby-forum.com/t/problems-with-mediawiki-behind-nginx-apache-redirects-to-wrong-url/211710/2 "2011-09-11T20:46:07Z")

</div>

I have now a working (perhaps not optimized) solution.

1.) Add following variable to Mediawiki’s LocalSettings.php:  
$wgServer = ‘[https://servername](https://servername)’;

I found this tip finally at  
[http://www.cyberciti.biz/faq/mediawiki-fix-internal-server-host-names-redirect-using-wgserver/](http://www.cyberciti.biz/faq/mediawiki-fix-internal-server-host-names-redirect-using-wgserver/)

though they specify the entire server url with the path to the wiki,  
whereas I specify just the protocol and the server

2,) As Mediawiki urls look like:  
[https://servername/wiki/index.php/blablabla](https://servername/wiki/index.php/blablabla)  
I have to be sure, that all these urls get redirected to apache

this I changed my setup to:

```
location ~ \.(php)$ {
    include proxy.conf;
    proxy_pass http://127.0.0.1:8081;
}

location /wiki/index.php {
    include proxy.conf;
    proxy_pass http://127.0.0.1:8081;
}

location / {
    root /home/noma/web/nomassl;
    index index.html index.htm index.php;
}

```

Perhaps this post can help somebdoy else. I was searching for quite some  
time and was already close to giving up.

On 09/11/2011 08:13 PM, Gelonida N wrote:

> Hi,Well I have finally a (non optimized) setting, which is working.

On 09/11/2011 08:13 PM, Gelonida N wrote:

> - I setup nginx with https such, that it handles all files, except php  
> and get redirected to [http://servername:8081/wiki2/index.php/Main\_Page](http://servername:8081/wiki2/index.php/Main_Page)
> 
> proxy\_connect\_timeout 90;  
> proxy\_send\_timeout 90;  
> proxy\_read\_timeout 90;
> 
> proxy\_buffer\_size 4k;  
> proxy\_buffers 4 32k;  
> proxy\_busy\_buffers\_size 64k;  
> proxy\_temp\_file\_write\_size 64k;
> 
> Thanks in advance for any pointers.
