Issue with reverse-proxy

Hello Team,

I have setup XWiki docker behind a reverse proxy.

XWiki needs to be accessible via https protocol, which must be reverse proxy with http.
Here are the setting in httpd.conf:

ProxyPass /xwiki http://xwiki:8080/xwiki connectiontimeout=300 timeout=300
ProxyPassReverse /xwiki http://xwiki:8080/xwiki

When I load XWiki, it shows 404 for all the resources it tries to load.

It seems that XWiki is not able to load any resources due to reverse-proxy setup. Can you please?
Thank you in advance for your help

XWiki%20Issue

Hi, I’ve just googled and found these resources:

Hope it helps

Actually one thing to know, the xwiki docker images currently deploys XWiki as ROOT webapp (i.e. without the /xwiki/ part).

See also https://jira.xwiki.org/browse/XDOCKER-74

Thus the following has no chance of working AFAICS:

Hello Vincent,

Thank you for your answer. I tried removing /xwiki from reverse proxy setup, but it did not help.

ProxyPass /xwiki http://xwiki:8080 connectiontimeout=300 timeout=300
ProxyPassReverse /xwiki http://xwiki:8080

You are right that XWiki docker is deployed as ROOT webapp in apache server. Is there any configuration which must be updated in order to inform XWiki that it must locate resources in the ROOT folder?

XWiki is setup behind an Apache server reverse proxy.

Thanks in advance.

Hello,

I want to ask if there is some progress in order to solve this issue.
We are just solving similar trouble but with Debian installation and we would really appreciate some help.

Thank you.

What is your proxy?

I have an installation of Apache front-ending to my tomcat9/xwiki installation and it works without problem.

I also have an nginx frontend to another tomcat9 installation that works (almost) without problem.

1 Like

Thank you for answer and sorry for five days break.
We proceeded into a function state using this approach:

  1. Virtual www settings configuration file added to /etc/apache2/SitesEnabled
  2. Into content of file we added: https://dubnik.wordpress.com/2018/11/08/how-to-apache-reverse-proxy-with-xwiki/
  3. And edited ServerName and filled it with our domain information
  4. Modules mod_proxy and proxy_a2enmod installed

But I wonder what is the best approach just serving domains to sub-wikis on one server, which is especially the thing I am trying to achieve.
Now we just set domain to main-xwiki and redirection from it’s homepage to sub-wiki’s homepage, which is not proper IMO (especially in multiple sub-wikis set to multiple domains).

Perhaps you could give me a bit more information so I can help you debug this

  • where is your apache proxy server running and what port?
  • where is your tomcat/xwiki installation running? Is it the same machine as the apache proxy, or a different machine? (I have examples of both configurations)

Next question - when you say “serving domains to sub-wikis on one server” could you be explicit in what you mean? Do you mean…

subdomain1.example.com -> wikiserver/
subdomain2.example.com -> wikiserver/subwiki1
subdomain2.example.com -> wikiserver/subwiki2

or do you mean

mydomain.example.com/xwiki -> wikiserver/xwiki
mydomain.example.com/xwiki/subwiki -> wikiserver/xwiki/subwiki

Both are possible, but the latter is much simpler to configure.

1 Like

Port 80
Apache and XWIKI are located on same machine.

I mean the first one. We have for example: domain.domainforuse.eu and we need to serve it to sub-wiki.

So, if I understand correctly, you have the following:
http://example.com:8080/xwiki/bin/view/Main/
http://example.com:8080/xwiki/wiki/subwiki1/view/Main/
http://example.com:8080/xwiki/wiki/subwiki2/view/Main/

and you want access the subwikis as:
http://subwiki1.example.com/
http://subwiki2.example.com/

Is that correct? I really need to make sure I understand exactly what you want, otherwise the configuration I give won’t be of any use at all.

Assuming that the above is correct, can you confirm that you can access the subwikis via the tomcat urls without problem, e.g.
http://example.com:8080/xwiki/wiki/subwiki1/view/Main/
http://example.com:8080/xwiki/wiki/subwiki2/view/Main/

1 Like

Now we got exmpl.example.com targeted to main xwiki 12.34.56.78:8080/xwiki
And we did redirect from this main xwiki to subdomain’s homepage.
But we need to target exmpl.example.com to 12.34.56.78:8080/xwiki/wiki/subwiki to become it more expandable.
So the exmpl.example.com will be targeted to 12.34.56.78:8080/xwiki/wiki/subwiki with possibility to expand.

Thank you,
svrl

Possible. But you will need a different apachce vhost configuration for each subdomain.

Give me some time to make a working example for you.

1 Like

ok, turns out it’s easier than I thought… I’m writing up the details now

The setup:
server

subdomains:

Step 1: Get your tomcat and subwikis running. Verify.

Step 2: get your apache configuration correct. Verify.

Step 3: get your apache vhosts configuration correct.

Configurations, with only the bare minimum listed.

#/etc/apache/sites-enabled/111-wikiserver.conf

<VirtualHost wikiserver.example.com:80>
        ServerName wikiserver.example.com
        DocumentRoot /var/www/wikiserver
        <Location "/xwiki">
                ProxyPreserveHost On
                ProxyPass  http://127.0.0.1:8080/xwiki
                ProxyPassReverse http://127.0.0.1:8080/xwiki
        </Location>
</VirtualHost>

#/etc/apache/sites-enabled/222-subwiki1.conf

<VirtualHost subwiki1.example.com:80>
        ServerName subwiki1.example.com
        DocumentRoot /var/www/subwiki1
        <Location "/xwiki">
                ProxyPreserveHost On
                ProxyPass  http://127.0.0.1:8080/xwiki
                ProxyPassReverse http://127.0.0.1:8080/xwiki
        </Location>
</VirtualHost>

#/etc/apache/sites-enabled/222-subwiki2.conf

<VirtualHost subwiki2.example.com:80>
        ServerName subwiki2.example.com
        DocumentRoot /var/www/subwiki2
        <Location "/xwiki">
                ProxyPreserveHost On
                ProxyPass  http://127.0.0.1:8080/xwiki
                ProxyPassReverse http://127.0.0.1:8080/xwiki
        </Location>
</VirtualHost>

Verify.

To make sure your vhosts are configured correctly, I dump an index.html file in the 3 DocumentRoot directories. The index.html file is a single line with only the text “<h1>[servername]</h1>” where [servername] is the domain name of the vhost. If I access http://servername/ and I get the right content back, then I know apache is configured properly.

Step 4: Configure tomcat/xwiki to use hostname based subwikis (reference here)

And that should do it.

Keep in mind the following things:

  1. The following urls won’t work correctly after doing step 4. You’ll get an ugly error message. You can intercept that call and redirect it to the correct server if you wish, but I wouldn’t worry about it too much.
  2. configuring SSL is left as an exercise to the reader. I recommend using the “letsencrypt” software to manage the settings for you automatically with apache. You configure your http hosts and it will do the rest.
  3. tomcat has three ways to support connections from apache; via
    1. http
    2. ajp
    3. and mod_jk

Forget 3, as it is an old method.

If you use 1 (it’s simple and is easier to debug problems between apache and tomcat), then I suggest you bind Tomcat only to 127.0.0.1 to make sure not to expose your tomcat instance to the world. I only bind Tomcat to a public ip when I am testing things out. In the above example, we’re using this method.

The mod_ajp connection is a binary protocol that is supposedly more efficient to allow tomcat and apache to communicate. You can find the details in the /etc/tomcat9/server.xml. Search for AJP. You can then configure apache to proxy to ajp://127.0.0.1:8009/xwiki instead of http://127.0.0.1:8080/xwiki/.

When you have that working, you can disable Tomcats http connector.

Finally, adding a new wiki should be as simple as creating a new subwiki, and creating a new apache vhost configuration file with the details updated for the new subwiki name.

If anyone with more experience in this matter has any suggestions, corrections or updates, they are most welcome to share them. I only just tested this out now and while it seems to work, I may have missed something important.

1 Like

Thank you very much :slightly_smiling_face:.
It is very nice amount of comprehensive information provided to my case. I will test it and give you feedback as fast as possible.

Hello, I will try to sum up my feedback:

After some settings to Apache I am able to reach parent wiki and its subwikis like this as I was before.

I understand you are saying to set vhosts in Apache to every wiki or subwiki which is need to do like this. But I am just really confused how should I save, move, symlink or just copy subwiki into this folder:

My xwiki is installed using debian installation process (on official docs) and it is installed in: usr/lib/xwiki, usr/share/xwiki, etc/xwiki and var/lib/xwiki/data. And what is more I don’t understand how should I trace the subwiki in filesystem, when all I can trace is the whole xwiki farm.

This was just no problem.
.
.
If I would follow your example, will I be able to have other apps in Tomcat next to this XWIKI settings? Or do I have to have XWIKI on separate server? I know that I need to have only one XWIKI on server without using virutal server or docker solution.
.
.
.
I just need to have parent xwiki accessible with IP like 12.34.56.67:8080/xwiki and my subwiki in this wiki to have to be set to my domain like: 12.34.56.67:8080/xwiki/wiki/mysubwiki -> somepart.maindomainpart.com, that’s all. I have the Apache set (I hope correctly), setting the configuration of xwiki files is very possible. I just don’t understand that part with DocumentRoot. I have found some other guides or steps on the internet and I think it was not solved at all. How can I in most straight way connect my domain to my sub-xwiki? :slight_smile:

DocumentRoot /var/www/subwiki1

I did this for testing purposes only.

You don’t have to have a different document root for every subwiki vhost.

The only reason I did this was to make sure that I could test my apache vhost installations to make sure they were configured properly. Once I knew it was configured properly, I could use the same DocumentRoot for all subwiki vhosts.

The choice to do that or not, is up to you. It’s not necessary and has no other affect on the xwiki installation as it is only an apache configuration.

I’m afraid I don’t understand what you mean. The more I think about it, the more I think the question doesn’t matter.

Yes. If you understand how to install additional servlets in Tomcat, then it’s very simple. However, that’s beyond the scope of this explanation.

Some people will say “don’t do it” and some people will say “it’s fine”. As long as your Tomcat JVM has enough memory and CPU, there shouldn’t be an issue.

If you look at those domains/urls, that’s exactly what you want, isn’t it? As long as you followed the previous steps, confirmed that everything works at each step, then you will have each subwiki served by their own subdomains (#2 and #3 in the quoted list above)

In fact, the minimum necessary urls are:

  1. http://wikiserver.example.com/xwiki/
  2. http://subwiki1.example.com/xwiki/
  3. http://subwiki2.example.com/xwiki/

And if adding /xwiki to the url is still too much, then you can make a single DocumentRoot that is identical for all vhosts and added in the following index.html:

<html>
<head>
    <title>xwiki AutoRedirect</title>
    <meta http-equiv="refresh" content="0; url=/xwiki/bin/view/Main/" />
</head>

<body>
<h1>xwiki</h1>
<p>redirecting to the <a href="/xwiki/bin/view/Main/">xwiki</a></p>

</body>
</html>

This will cause all the browsers automatically to redirect to the xwiki installation. Also, since the url doesn’t specify the domain but only path, then the same file will work for all the xwikis, as long as you have completed step 4 correctly. Thus your urls can be as simple as:

  1. http://wikiserver.example.com/
  2. http://subwiki1.example.com/
  3. http://subwiki2.example.com/

There may be a better way to do this, but this works well enough.


Otherwise, the DocumentRoot setting is a non issue. As I said, it was only for testing.

This test installation was done under Ubuntu Server 18, which is almost identical to Debian, so you shouldn’t have any trouble using this configuration.

Does that help your understanding?

I am very thankful to you because of these explanation you are providing to my case. I don’t think this is “too complex” or just “too much”. I just don’t understand some steps because I am pure Tomcat beginner and I have worked only with Apache, PhP, MySQL and so on. And I don’t want to bother you more than needed.

Sorry for misunderstanding, I use Ubuntu 18.04, but I used this Debian/Ubuntu installation as mentioned before.

But I just don’t understand to these steps:

So instead of this I should fill there the real location of war files of XWIKI?

To set domain to sub-wiki only I will follow only this, right? But I am anyway targeting xwiki parent on loopback but there is no target of actuall sub-wiki. That is why I asked you about the filesystem presence of sub-wiki:

But there is no other trace of actuall sub-wiki than in the: /var/www/subwiki1 of your text, which you said is only an example. So to transfer your example to my situation I need to know what instead of your example I should fill there. I am very sorry for being confused, but I just don’t get it.

After I have follwed the steps you made I just ended with:
subdomain.maindomain.com = 12.23.54.78:8080/xwiki
which is the main wiki, not subwiki.

It might be easier if I logged into your server and configured it for you. Either that, or I send you the virual machine where everything is already configured.

The problem is your lack of experience. It’s like trying to run before you’ve even learned how to walk.


There are two ways you could run xwiki. You could serve it from Tomcat directly, or you could have Apache proxy the xwiki requests for Tomcat. The configuration I described is the last one because while Tomcat is a very good application server, it is not a good webserver.

So, all requests to xwiki/tomcat in my configuration are first handled by apache, and then only the xwiki requests are forwarded to Tomcat.

We use Apache to define our virtual hosts and subdomains because it’s easier than doing it in tomcat (I actually forget how to do that in tomcat, but that doesn’t matter). Once apache is configured properly, then the requests are proxied and sent to tomcat where, as long as tomcat is configured properly, it does the right thing and sends the requests to the appropriate wiki/subwikis.

In Tomcat, there is almost nothing to configure as almost everything is already configured for you.

The steps you listed that you do not understand are for the Apache configuration only. Apache doesn’t care about xwiki, or where the jar files are. It only needs to know what requests to send, and where to send those requests.

If you follow my steps listed above, and you test every link I ask you to test, then your configuration will work. I am not sure how I can make those instructions any simpler.

If you do anything difference from what I’ve listed, then I don’t know what will happen.

Thank you for more wide explanation of this issue. With all respect I think that I have already knew about this issue like it is. After I have done some number of Apache settings for PhP application I still have some deficit (probably) in Apache to Tomcat settings. Problem persisted in setting the Apache to Tomcat for sub-wiki as it itself where decent ambiguity is present as here as on the internet (in other forums). Everybody has been able to set it to parent wiki not to subwiki. Although I am immensely grateful for your time invested to me, but I still have to do testing and research for this issue. I think we just didn’t understood each other I need to set domain to subwiki where the domain has none text same with name of xwiki. It is more like: 123.asdf.com = 123.asdf.com/xwiki/wiki/jkljkl where “jkljkl” is name of subwiki. Do your settings actually work for particular subwiki? Or is it just working settings for Apache to Tomcat connections? I am deeply sorry, but this settings besides the “DocumentRoot” which you said is irrelevant does not wear any signs of particular subwiki aim, everything then is just set to /xwiki not /xwiki/wiki/jkljkl (example).

As I said, I am very grateful and I feel sorry for not solving this situation. I will try my best in upcoming days to solve this issue. I still think and there might be some kind of misunderstanding. I thank you for every advice you have gave to me so far.
Have a nice day.