[Guide] Nextcloud on Windows Server and Hyper-V

Hello there!

This is a how-to guide on NextCloud (HTTPS) on Windows Server, using IIS as a proxy, and Nexcloud running inside a Hyper-V Linux distro with Apache2.

This will not be a super fancy, in-depth tutorial guide, but it’s a good start for someone that have decent skills in both Linux and Windows server.

I’ve been struggling with this myself for quite some time, but now that it’s all up and running perfectly; I figured I’d write a basic guide in case I myself forget in the future…

I already assume you have the following set-up:

  1. Windows Server (Host OS)
  2. Hyper-V Instance of your preferred Linux distro inside that Windows Server; I run Ubuntu myself.
  3. Port-forwarded your routers port 80 and 443 to the Windows Server IP-adress.

Now then…

IIS Pre-requisites

  1. Install URL Rewrite Module 2
  2. Install ARRM

Set up ARRM
Configure ARRM as follows:

Proxy site configuration
You do not need to do something with the rewrite module as long as it is installed. But, we need to set up a site that will act as the proxy to Nextcloud.

  1. Create a new IIS site
  2. Assign it as hostname; such as “cloud.youdomain.com” or something; whatever you have in mind, and have created a DNS record for at your registrar.
  3. Bind http, all unassigned; port 80.
  4. Run WACS Let’s Encrypt to create the SSL Certificate and configure the IIS site binding with port 443. (Alternatively, create the SSL binding manually if you already have a certificate for your DNS name)
  5. When the site is created, open the sites file root (Right click the site → Explore)
  6. Create a file called “web.config”, and paste the following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters="" />
  </system.web>
  <system.webServer>
    <rewrite>
      <rules useOriginalURLEncoding="false">
        <rule name="Https" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" appendQueryString="false" />
        </rule>
        <rule name="To nextcloud" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^ON$" />
          </conditions>
          <action type="Rewrite" url="http://192.168.0.4{UNENCODED_URL}" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>
    <security>
      <requestFiltering allowDoubleEscaping="true">
        <requestLimits maxAllowedContentLength="4000000000" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>
  1. Replace my IP 192.168.0.4 with whatever IP your Hyper-V instance of Linux has. What this config does is basically takes all requests going to IIS, and forwards them to the Apache2 installation in your Linux VM.

Apache2 configuration
Now… I assume you’ve already set up Nextcloud (HTTP, Without SSL) on the Linux distro VM; using the easy peasy guide made by Nextcloud you find HERE.
Bascially, you should be able to log in, and use nextcloud as intended from inside your Linux VM, accessing it using localhost or the Linux VMs IP adress.

We’re going to finalize the setup, and configure Apache2 to redirect all traffic to IIS running on your Windows host; as well as fix the Nextcloud config file a bit.

Nextcloud config file
Your config file should look like this:

Apache2 config
The nextcloud.conf (in sites-enabled) file, or whatever you named your Apache2 site, should look like this:

With all that done, in theory; at least in my case; Nextcloud now should operate as intended, and work like a charm!