Apache - treat url path as virtual host

前端 未结 4 1604
不知归路
不知归路 2021-02-04 04:18

The problem is that I have only one domain name on which 3 different products need to be run (2 of them PHP based, 1 python). So what I need to do is to treat path in url as dif

4条回答
  •  情深已故
    2021-02-04 04:55

    This example explains how to assign different PHP version per directory, it can also be adapted to add Python support by running Python interpreter as fast_cgi on particular port

    For the purpose of the example I assume there is separate directory for each PHP version and they are named according to PHP version that runs them, but this can be adjusted

    mkdir /home/user/www
    mkdir /home/user/www/5.6.5
    mkdir /home/user/www/7.0.2
    mkdir /home/user/www/7.0.4
    mkdir /home/user/www/7.0.6
    

    create symbolic links to directories that should be handled by different PHP versions

    sudo ln -s /home/user/www/7.0.2/ /var/www/html/7.0.2
    sudo ln -s /home/user/www/7.0.4/ /var/www/html/7.0.4
    sudo ln -s /home/user/www/7.0.6/ /var/www/html/7.0.6
    

    then add following lines to /etc/apache2/sites-enabled/000-default.conf in default virtual host *:80

    (for your need you can setup one more fast cgi handler here for the website that requires Python), I assume php 5.6.5 runs on port 9999, 7.0.2 runs on port 9998 etc...

    DirectoryIndex index.html index.php
    ProxyPassMatch ^/5.6.5/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9999/var/www/html/
    ProxyPassMatch ^/7.0.2/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9998/var/www/html/
    ProxyPassMatch ^/7.0.4/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9997/var/www/html/
    ProxyPassMatch ^/7.0.6/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9996/var/www/html/
    

    assuming your server is pointed by example.com you can test it on

    http://example.com/5.6.5/
    http://example.com/7.0.2/
    http://example.com/7.0.4/
    http://example.com/7.0.6/
    

提交回复
热议问题