Score:0

Apache VirtualHost Same domain for Front and API

lb flag

I have a multi-tenant application that is resolved using subdomains with the pattern *.localhost. The front-end of the application is accessible at http://localhost:3000/.

To achieve the desired functionality, I need to proxy all requests that do not contain the /api path segment to the front-end URL, while requests with the /api path segment should be routed to the backend API.

For example:

  • tenant1.localhost should be proxied to the front-end.
  • tenant1.localhost/api should be proxied to the backend API.

I have attempted to configure the Apache server with the following settings:

        <VirtualHost *:80>
            ServerName localhost
            ServerAlias *.localhost

            RewriteEngine On
            RewriteCond %{HTTP_HOST} ^([^.]+)\.localhost$
            RewriteRule ^/api(/.*)?$ http://%1.localhost/api$1 [P]

            # Exclude phpMyAdmin from being proxied
            ProxyPass /phpmyadmin !

            # Serve http://localhost:3000/ for all other requests
            ProxyPass / http://localhost:3000/
            ProxyPassReverse / http://localhost:3000/

        </VirtualHost>

        <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            DocumentRoot "C:/Users/api/public"
            ServerName api.localhost
            ServerAlias *.localhost/api
            <Directory "C:/Users/api/public">
                Options All
                AllowOverride All
                Require all granted
            </Directory>
        </VirtualHost>

However, this configuration is not working as expected.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.