GGCE with IIS
Internet Information Services (IIS) can be used on Windows to handle SSL encryption and relay HTTP requests to GGCE docker containers by utilizing URL Rewrite and Application Request Routing (ARR) features:
- Install URL Rewrite.
- Install Application Request Routing. ARR depends on URL Rewrite. Ensure URL Rewrite is installed prior to installing ARR.
This will add Server Farms option to IIS where you'll define two docker-powered groups: one for GGCE Web interface ggce
and one for GGCE API server ggce-api
:
Then you'll define routing rules that will relay website traffic to these farms based on HTTP_HOST
header.
Let's start by opening the Internet Information Service (IIS) Manager by hitting the Start button and searching for "IIS".
Server Farms
The folowing steps assume that IIS and Docker are running on the same machine. If Docker is running on another computer then please replace 127.0.0.1
with the name or IP of that machine.
GGCE API Server
GGCE API Server in Docker is direcly accessible at http://127.0.0.1:8080
regardless of the friendly DNS name. You will register a new Server Farm in IIS with the name ggce-api
with one server at 127.0.0.1
that listens on HTTP port 8080
:
- Right click on "Server Farms" and select "Create Server Farm"
- In the "Specify Server Farm Name" dialog:
- Give this farm the name
ggce-api
. - Click Next.
- In the "Add server" dialog:
- Specify Server addresss
127.0.0.1
(for localhost). - Open Advanced Settings and specify httpPort
8080
.
- Click Add button (to add
127.0.0.1:8080
to the server list). - Click Finish button.
- Click No on any following dialogs.
GGCE Web
GGCE Web in Docker is at http://127.0.0.1:3000
. Add another Server Farm in IIS with the name ggce
with one server at 127.0.0.1
that listens on HTTP port 3000
:
- Right click on "Server Farms" and select "Create Server Farm"
- In the "Specify Server Farm Name" dialog:
- Give this farm the name
ggce
. - Click Next.
- In the "Add server" dialog:
- Specify Server addresss
127.0.0.1
(for localhost). - Open Advanced Settings and specify httpPort
3000
.
Same as above, but with port3000
! - Click Add button (to add
127.0.0.1:3000
to the server list). - Click Finish button.
- Click No on any following dialogs.
At this point you should have two server farms declared in your IIS:
Routing traffic from IIS to GGCE
After setting up the backend server farms you need to declare a routing rule that will direct traffic from IIS to Docker.
Routing for GGCE API Server
- Select
ggce-api
server farm. - Open "Routing rules":
- Enable both Use URL rewrite... and Enable SSL offloading options and click URL Rewrite on the right, under Actions. Confirm that you want changes saved, if prompted:
- Open the newly created routing rule:
- Use default "Match URL" configuration:
- Requested URL: Matches the Pattern
- Using: Wildcards
- Pattern:
*
- Expand "Conditions" and add:
- Condition input:
{HTTP_HOST}
- Check if input string: Matches the Pattern
- Pattern: Enter domain name for GGCE API (example uses
ggceapi.in.croptrust.org
):
- Use default configuration in "Actions":
- Click Apply and go back to list of rules
Routing for GGCE Web
Repeat the steps to add routing for GGCE Web server farm:
- Select
ggce
server farm. - Open "Routing rules".
- Enable both Use URL rewrite... and Enable SSL offloading options and click URL Rewrite on the right, under Actions. Confirm that you want changes saved.
- Open the newly created routing rule.
- Use default "Match URL" configuration:
- Requested URL: Matches the Pattern
- Using: Wildcards
- Pattern:
*
- Expand "Conditions" and add:
- Condition input:
{HTTP_HOST}
- Check if input string: Matches the Pattern
- Pattern: Domain name for GGCE website
ggce.in.croptrust.org
- Use default configuration in "Actions":
- Click Apply and go back to list of rules
The resulting URL Rewrite configuration now has two rules for routing HTTP traffic to respective server farms:
Confirm that GGCE API is accessible through IIS at http://ggceapi.in.croptrust.org
and the Web at http://ggce.in.croptrust.org
.
Enable HTTPS
The final step is to enable HTTPS by adding a new binding to the Default Web Site
and adjusting the routing rule for https
.
You can use an existing wildcard certificate or generate/import a new SSL certificate to IIS in Server Certificates.
Preparing certificate for import
In case you need to create the pfx
certificate file required by IIS from .key
and .pem
(or .cer
) files you can use:
openssl pkcs12 -export -in ggce.in.croptrust.org.pem -inkey ggce.key -out ggce.in.croptrust.org.pfx
Update Default Web Site bindings
- Edit bindings:
- Add binding for GGCE API
- Type: https
- IP address: All Unassigned
- Port: 443
- Host name: Enter domain name for GGCE API (example uses
ggceapi.in.croptrust.org
) - Enable Require Server Name Identification (SNI)
- SSL certificate: Select the certificate to use
- Repeat the steps for GGCE Web:
- Type: https
- IP address: All Unassigned
- Port: 443
- Host name: Enter domain name for GGCE Web (example uses
ggce.in.croptrust.org
) - Enable Require Server Name Identification (SNI)
- SSL certificate: Select the certificate to use
Confirm that GGCE API is accessible through IIS at https://ggceapi.in.croptrust.org
and the Web at https://ggce.in.croptrust.org
.
Update routing rules
IIS needs to be configured to add X-Forwarded-Proto
HTTP header to GGCE API to ensure GGCE stays on https when redirecting:
- Select
ggce-api
server farm. - Open "Routing rules":
- Click URL Rewrite on the right.
- Open the existing routing rule for
ggce-api
. - In section "Server variables" click Add and specify:
- Server variable name:
HTTP_X_FORWARDED_PROTO
- Value:
https
- Enable Replace existing value
- Click "OK"
- Server variable name:
The resulting Server variables category will now add the X-Forwarded-Proto: https
header and ensure redirects stay secure:
You may add the same setting to the rules for GGCE Web, but it is not a requirement.
Update GGCE configuration
ggce.yml
While the two sites are now accessible, they will not communicate properly until ggce.yml
file is updated
to reflect the new URLs!
Update only the following settings in your ggce.yml
:
services:
ggce-api:
environment:
- BASE_URL=https://ggceapi.in.croptrust.org
- FRONTEND_URL=https://ggce.in.croptrust.org
ggce-ui:
environment:
- API_URL=https://ggceapi.in.croptrust.org
- ORIGIN=https://ggce.in.croptrust.org
After updating ggce.yml
you need to apply the changes with:
docker compose -f ggce.yml up -d
Other Server Farm settings
You may wish to update the following settings of both Server Farms:
- Under "Caching":
- Query string support: Do not cache.
- Under "Proxy":
- Time-out: You may wish to increase the timeout to 300s.
- Always disable Reverse rewrite host in response headers.
Server health check
You can optionally declare a health check for each individual server farm by adding http://localhost/robots.txt
as the URL Test.