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 [email protected]

    DocumentRoot /var/www/example

    DirectoryIndex /index.html index.html

    #<LocationMatch "^/site2.*">
    #    RewriteEngine on
    #    RewriteRule . /example2/index.html [L]
    #</LocationMatch>

    AliasMatch "/site2(.*)" "/var/www/site2$1"
    <Directory /var/www/site2>
        Require all granted
        AllowOverride all
    </Directory>


    # 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 "a2disconf".
    #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 "/site2" "/var/www/site2"
    <Directory /var/www/site2>
        Require all granted
        AllowOverride all
    </Directory>
</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?

4
  • 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
    Commented Jul 18, 2017 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
    Commented Jul 18, 2017 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
    Commented Jul 19, 2017 at 7:09
  • It worked! Thats part 1. Now figure out part 2.
    – matglas86
    Commented Aug 9, 2017 at 15:54

1 Answer 1

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.

5
  • I tried this with no success.
    – matglas86
    Commented Jul 18, 2017 at 12:25
  • @matglas86 The directory /var/www/site2 must be readable for www-data also you must restart the server.
    – pa4080
    Commented Jul 18, 2017 at 12:28
  • I just added my test config and my results.
    – matglas86
    Commented Jul 18, 2017 at 12:35
  • If you make mention of the DirectoryIndex correction you gave in the comment I'll give kudos'.
    – matglas86
    Commented Aug 10, 2017 at 8:43
  • Hi, @matglas86, I've updated my answer. Unfortunately I'm still cannot help with Question 2.
    – pa4080
    Commented Aug 10, 2017 at 9:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .