Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple websites, single IP address with Intraweb and Apache
#1
Multiple websites, single IP address with Intraweb and Apache

There are a number of ways that you can serve multiple websites created using Intraweb from a single webserver and single public IP address. I am going to describe the way I set it up in case others find it useful. I'm not suggesting that this is the best or only way to do it, but it worked for me.

Step 1. Assign unique port numbers to your Intraweb applications. Do this by setting the Port property of the ServerController. For example, set application 1 to port 50000, application 2 to port 50001 and so on. Also set the AppName property of the ServerController. Note that this name cannot contain any spaces.

Step 2. Compile the Intraweb applications as a Windows service. You can set up your dpr file to easily switch between stand-alone executable (for use during development) and service (for deployment).

Code:
{$DEFINE SERVICE}
//{$DEFINE EXE}
program Application1;
uses  
  {$IFDEF EXE}
  IWRtlFix,
  Forms,
  UTF8ContentParser,
  IWMain,
  IWStart,
  {$ENDIF}
  {$IFDEF SERVICE}
  IWRtlFix,
  IWStart,
  {$ENDIF}
  Form1 in 'Form1.pas',   
  ServerController in 'ServerController.pas',
  UserSessionUnit in 'UserSessionUnit.pas';
{$R *.res}
begin  
  {$IFDEF EXE}  
  TIWStart.Execute(True);
  {$ENDIF}
  {$IFDEF SERVICE}
  TIWStart.Execute(False);
  {$ENDIF}
end.

Step 3. When you are ready to deploy, compile the application as a service and copy the .exe file to a suitable location on your webserver. Install the service application by running Application1.exe -install from a command line (this step only needs to be done once).
 
Step 4. Run the Windows Services Manager (press Start and type Services). The Services Manager will be your friend for the remainder of the setup process. Check in the Services Manager and you should see your application listed. You will find it listed under the AppName that you defined in step 1. Set its startup type to Auto and start if it’s not already running. 

Step 5. Install Apache. There are a number of places where you can download a Windows installer for the current version of the Apache HTTP server. Choose the 32-bit or 64-bit option as appropriate. Here’s the site that I used:

https://www.apachehaus.com/cgi-bin/download.plx

After installing Apache, check in the Services Manager to see if it is running (Apache HTTP Server).

Step 6. Purchase the domain names (from godaddy or another provider) and a public static IP address (from your ISP) if you don’t have one already.
Let’s say you purchase domain names application1.com and application2.com. You need to configure the name server records for both the domain names so that you have an “A” record which points to your webserver’s public static IP address. For example, you need an “A” record with host name application1.com pointing to your static IP address, and similarly for application2 you need an “A” record with host name application2.com pointing to the same IP address.

Note that it can take up to eight hours for the name server changes you make to take effect. In my case it took a couple of hours.

Step 7. Set up port forwarding on your broadband router so that port 80 is forwarded to your webserver. You will need to assign a local static IP address to your webserver to do this. For example, if you have assigned the static address 192.168.1.1 to your webserver, create a port forward in your router so that requests on port 80 are forwarded to 192.168.1.1.

Step 8. Edit the Apache configuration file. If you have installed Apache in the default location, the file you want to edit is this one:

C:\Apache24\conf\extra\httpd-vhosts.conf

Add the following lines:


Code:
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName application1.com
    ProxyPass / http://127.0.0.1:50000/
    ProxyPassReverse / http://127.0.0.1:50000/
</VirtualHost>
<VirtualHost *:80>
    ServerName application2.com
    ProxyPass / http://127.0.0.1:50001/
    ProxyPassReverse / http://127.0.0.1:50001/
</VirtualHost>

The NameVirtualHost directive tells Apache that we want it to listen on port 80 for requests to virtual hosts.

The first VirtualHost section tells Apache to take any requests that are made to the application1.com domain name and pass them on to port 50000 on the local machine. This is of course the port that your Intraweb application is listening on. Likewise, any requests made to application2.com are passed on to port 50001. Apache is acting as a “reverse proxy” in this case. Rather than allowing an internal application to access the internet via a proxy server, it takes requests from the internet and directs them to an internal application.

After saving the httpd-vhosts.conf file, restart Apache using the services manager.

That’s it. You can test locally by browsing to http://127.0.0.1:50000/ and http://127.0.0.1:50001/ and you should get the application1 and appliation2 websites respectively. If they are working, then try using the domain names you have registered.
When you need to update your website executable file, stop the application service, copy the new file over the old one and then start the service.
Reply
#2
That's a great contribution. IW works quite nicely with Apache as a Reverse proxy. Thanks for that!

I'd like to mention that you can also achieve the same effect (i.e. 2 or more applications running independently using the same IP and port) using Http.sys deployment which performs really well on Windows.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)