Configuring Apache reverse proxy server (Windows)

Preparations

In this tutorial, we will learn how to set up Apache on Windows and use it as the reverse proxy server to redirect requests to the PowerServer Web APIs running on the Kestrel server.

The Apache reverse proxy server can be set up on the same or different server from the PowerServer Web APIs and Kestrel. In this tutorial, the same server will be used.

In this tutorial, we will configure and use the following server environment and URLs. Be careful to use the correct port number and make sure the port is not occupied by any other program.


Step 1: Set up the server with the following OS and software (install the software in the order listed).

  • Windows Server 2019 (64-bit)

  • Visual C++ Redistributable

  • Apache HTTP Server 2.4.47

    The section Installing Apache HTTP Server has detailed installation instructions.

Step 2: Make sure the server can connect to the NuGet site: https://www.nuget.org (for installing PowerServer NuGet packages) and the following Appeon sites (through port number 80): https://apips.appeon.com and https://apipsoa.appeon.com (or https://apips.appeon.net and https://apipsoa.appeon.net) (for validating the PowerServer license).

Note

If the server connects to Internet through a proxy server, make sure to configure the proxy server settings in the PowerServer Web API as well (the ServerAPIs project > Server.json file > "ProxyOptions" block).

Step 3: Configure Windows Defender Firewall on the server to allow the port number (80 and 8080 in this tutorial or any port number you choose). The section "Configuring Windows Defender Firewall" has detailed instructions.

Configuring Apache

This section is to configure Apache as a reverse proxy server in a Windows machine.

Step 1: Go to the ..\Apache24\conf folder and open the httpd.conf file in a text editor.

Step 2: Add the following scripts to the end of the httpd.conf file.

This is to configure Apache as a reverse proxy server which will redirect requests made to the URL: http://172.16.100.35:8080/ to the PowerServer Web APIs running on Kestrel at http://172.16.100.35:6000/.

# Listen on port 8080 or any port you choose. Make sure it is not used by any other program. 
<VirtualHost *:8080> 
 ProxyPreserveHost On
 ErrorLog logs\ps-error.log   
 CustomLog logs\ps-access.log common  
 # Pass all requests received at the root http://172.16.100.35/8080 to http://172.16.100.35:6000/ (PowerServer Web APIs running on Kestrel server) and in reverse.
 ProxyPass / http://172.16.100.35:6000/ 
 ProxyPassReverse / http://172.16.100.35:6000/
</VirtualHost>

Step 3: Locate the following line in the httpd.conf file and specify the port number: 80 (or any port you choose) is used to access the static Web files on the Apache HTTP server, 8080 is used to access Web APIs (according to the reverse proxy setting in step 2, requests made to 8080 will be forwarded to 6000.)

Change

Listen 80

To

Listen 80
Listen 8080

Tip: In Windows, you can execute the command "netstat -ano | findstr 8080" to check if the port number is occupied by any other program.

Step 4: Make sure the following lines are NOT commented out in the httpd.conf file.

LoadModule negotiation_module modules/mod_negotiation.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so

Step 5: Check if any syntax error in httpd.conf.

cd C:\Apache24\bin
httpd -t

Step 6: Restart Apache for the changes to take effect.

httpd -k restart

Step 7: View the ..\Apache24\logs\error.log file to make sure Apache is started successfully.

[Wed Jun 02 00:46:00.547040 2021] [mpm_winnt:notice] [pid 1556:tid 696] AH00455: Apache/2.4.47 (Win64) configured -- resuming normal operations
[Wed Jun 02 00:46:00.547040 2021] [mpm_winnt:notice] [pid 1556:tid 696] AH00456: Apache Lounge VS16 Server built: Apr 24 2021 11:08:47
[Wed Jun 02 00:46:00.547040 2021] [core:notice] [pid 1556:tid 696] AH00094: Command line: 'c:\\apache24\\bin\\httpd.exe -d C:/Apache24'
[Wed Jun 02 00:46:00.547040 2021] [mpm_winnt:notice] [pid 1556:tid 696] AH00418: Parent: Created child process 4860
[Wed Jun 02 00:46:01.143540 2021] [mpm_winnt:notice] [pid 4860:tid 728] AH00354: Child: Starting 64 worker threads.

Step 8: If you have set up a firewall on the server, configure the firewall to allow port 8080 (by following instructions in "Configuring Windows Defender Firewall").

Note

If the firewall blocks the port number, you will have the following error when running the application.


Modifying and re-deploying the PowerServer project

The following modifications are made to the PowerServer project created in the Quick Start guide. If you have not created a PowerServer project yet, please follow the instructions in the Quick Start guide to create one.

Step 1: Modify the Web API URL to point to the Apache reverse proxy server.

On the Web APIs tab of the PowerServer project painter, specify the URL of the Apache reverse proxy server, for example, http://172.16.100.35:8080 in this tutorial. All requests for PowerServer Web APIs will be first made to http://172.16.100.35:8080 and then redirected by the Apache reverse proxy server to the PowerServer Web APIs running on Kestrel server (for example, http://172.16.100.35:6000).


Step 2: Select a Web server for deploying the app files.

On the Client Deployment tab of the PowerServer project painter, select a local or remote Web server (IIS, Apache, Nginx, etc.) you have configured properly.

The Web server and the Apache reverse proxy server can reside in the same or different machine. If the Web server is an Apache HTTP server, it can be the same or different server instance with the Apache reverse proxy server.

In this tutorial, we use the same Apache server instance as the Apache HTTP server and the reverse proxy server.

  • If you choose the "Directly deploy to the server" option, make sure you have configured the FTP settings properly for the server. See Setting up Apache on Windows > Installing FTP server for detailed instructions.

  • If you choose the "Package the compiled app and manually deploy later" option, follow the instructions in Packaging and copying the client app.


Step 3: Save the PowerServer project settings and then build and deploy the PowerServer project for the changes to take effect.

Starting Web APIs (in development environment)

In this tutorial, we will directly run the PowerServer Web APIs in the development environment, by using either of the following methods:

  • Execute the "dotnet run --project PowerServer19\ServerAPIs\ServerAPIs.csproj" command, or

  • Open the PowerServer C# solution in the SnapDevelop IDE and then click the Run button.

PowerServer Web APIs is running as a standalone console application on its own internal Kestrel web server.

Make sure the PowerServer Web APIs is running on the correct IP address and port number. For example, http://172.16.100.35:6000/ in this tutorial. You may modify the port number in the launchSettings.json file of the ServerAPIs project of the PowerServer C# solution when running in the development environment.

If the server connects to Internet through a proxy server, make sure to configure the proxy server settings in the PowerServer Web API as well (the ServerAPIs project > Server.json file > "ProxyOptions" block).


When you run the application (http://172.16.100.35:80/pssales in this tutorial), you will be able to see from the console that the requests are going through successfully and the requests are originally made to the Apache proxy server (http://172.16.100.35/8080 in this tutorial).