2

I have one domain like http://example.com. This results in a page loaded from /var/www/example. Now I want all requests to http://example.com/site2 to be resolved to the folder /var/www/site2.

This is the basic idea and I tried to accomplish it like this (which did not work):

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
DocumentRoot /var/www/example

DirectoryIndex /index.html index.html

#&lt;LocationMatch &quot;^/site2.*&quot;&gt;
#    RewriteEngine on
#    RewriteRule . /example2/index.html [L]
#&lt;/LocationMatch&gt;

AliasMatch &quot;/site2(.*)&quot; &quot;/var/www/site2$1&quot;
&lt;Directory /var/www/site2&gt;
    Require all granted
    AllowOverride all
&lt;/Directory&gt;


# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with &quot;a2disconf&quot;.
#Include conf-available/serve-cgi-bin.conf

</VirtualHost>

I tried using the Alias directive and LocationMatch to rewrite stuff to the correct URL when arriving at the /site2 URL. This was my conf. At http://example.com/site2/ it would result in the index.html from http://example.com/. Only when requesting http://example.com/site2/index.html.

<VirtualHost *:80>
    DocumentRoot /var/www/example
DirectoryIndex /index.html index.html

Alias &quot;/site2&quot; &quot;/var/www/site2&quot;
&lt;Directory /var/www/site2&gt;
    Require all granted
    AllowOverride all
&lt;/Directory&gt;

</VirtualHost>

I would also like to have all PHP requests passed to their own FPM pool. The requests for http://example.com should be passed to fcgi://127.0.0.1:9000 and the request for http://example.com/site2 should go to fcgi://127.0.0.1:9001.

How can I achieve this?

  • I cannot understand "Question 2". What you mean requests should go to localhost? The localhost (loopback interface) is accessible only from the local machine. – pa4080 Jul 18 '17 at 12:04
  • @pa4080 I updated my question. They should be passed to fpm on fcgi://127.0.0.1:9000 and fcgi://127.0.0.1:9001. – matglas86 Jul 18 '17 at 12:17
  • Hi, matglas86, I'm thinking about Question 1. Could you try to remove /index.html from DirectoryIndex. Usually you don't need path and maybe this is the reason why Apache shows only the index from the the main directory. – pa4080 Jul 19 '17 at 07:09
  • It worked! Thats part 1. Now figure out part 2. – matglas86 Aug 09 '17 at 15:54

1 Answers1

1

According to "Question 1)":

  • you should add an alias:

    Alias /site2 /var/www/site2
    <Directory /var/www/site2>
        Require all granted
        AllowOverride all
    </Directory>
    
  • The DirectoryIndex directive reads the statements as 'absolute' filenames. I mean with this syntax:

    DirectoryIndex /index.html index.html
    

    DirectoryIndex will check if index.html, located in DocumentRoot=/, exists and will display it if yes, and will ignore next statements. So if this record (/index.html) is not intended it is wrong. Some examples here.

pa4080
  • 29,831