2

I have two questions.

(had to remove some http:// in my example url's because I don't have enough reputation yet to have mor then 1 url in my question. so it says //example.)

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

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

<VirtualHost *:80>
    ServerAdmin webmaster@example.com

    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 Location match to rewrite stuff to the correct url when arriving at the /site2 url. This was my conf. At //example.com/site2/ it would result in the index.html from //example.com/. Only when requesting //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>

Question 2) If 1 works then I would like to have all php request passed to its own fpm pool. The requests for example.com should be passed to fcgi://127.0.0.1:9000 and the request for //example.com/site2 should go to fcgi://127.0.0.1:9001.

[EDITED] (Changed reference for fpm fcgi.) [EDITED] (Added conf based on Alias directive.)

matglas86
  • 33
  • 5
  • I cannot understand "Question 2". What you mean requests should go to `localhost`? The `localhost` ([loopback interface](https://askubuntu.com/questions/247625/what-is-the-loopback-device-and-how-do-i-use-it)) 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,351
  • 10
  • 85
  • 161