edit-icon download-icon

Multi-site configuration

Last Updated: Feb 06, 2018

Target

A user has two domain names, which are aaa.yoursite.com and bbb.yoursite.comThe user wants to open different subdirectory website programs when accessing the above two sites.

Steps

Upload the code

Let’s assume that the user has already uploaded code for the two sites to the subdirectories /home/www/htdocs/aaa and /home/www/htdocs/bbb. For testing convenience, we have placed two index.html files with different content in the subdirectories, and we have modified the permission of the two directories and subdirectories to www:www.Refer to command: chown www:www -R /home/www/htdocs

Modify the configuration file

Modify the httpd.conf configuration file to activate virtual nodes. Detailed steps are as follows: vi /usr/local/apache/conf/httpd.conf

As shown in the preceding figure, move the cursor to the start of the row in the red box,enter x and delete #, as shown in the following figure:Include conf/extra/httpd-vhosts.confand then move to the start of ProxyPassMatch, and add # in the front (comment out this row). At last, modify the two corresponding rows as follows:

  1. Include conf/extra/httpd-vhosts.conf
  1. #ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/home/www/logs/php-fpm.sock|fcgi://127.
  2. 0.0.1/home/www/htdocs

Press shift+, enter x!, and then press the Return key to complete modification on the file.Modify the httpd-vhosts.conf configuration file Add # in front of the rows in the red box (comment out these rows), and add the following two nodes to the end.

  1. <VirtualHost *:80>
  2. ServerAdmin webmaster@serveradmin.com
  3. DocumentRoot "/home/www/htdocs/aaa"
  4. ServerName aaa.yoursite.com
  5. ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/home/www/logs/php-fpm.sock|fcgi://127.0.0.1/home/www/htdocs/aaa/
  6. </VirtualHost>
  7. <VirtualHost *:80>
  8. ServerAdmin webmaster@serveradmin.com
  9. DocumentRoot "/home/www/htdocs/bbb"
  10. ServerName bbb.yoursite.com
  11. ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/home/www/logs/php-fpm.sock|fcgi://127.0.0.1/home/www/htdocs/bbb/
  12. </VirtualHost>

Press shift+, enter w!, save and exit, as shown in the following figure.

Restart service

Restart Apache, the command is as follows:

  1. /usr/local/apache/bin/apachectl restart

Test the access

Finally, test the access

Thank you! We've received your feedback.