Home >Backend Development >PHP Tutorial >After registering a domain name, can multiple PHP projects be bound separately with multiple domain names?
I have registered several domain names. Can I bind multiple php projects running on apache deployed in the server separately with multiple domain names? How to bind?
I have registered several domain names. Can I bind multiple php projects running on apache deployed in the server separately with multiple domain names? How to bind?
It’s ok. Just use virtualhost.
First use A records to resolve all your domain names to the server’s IP
Edit the http-vhost.conf configuration
<code><VirtualHost *:80> DocumentRoot "D:/UPUPW_AP5.5/vhosts/hospital.com/web" ServerName hospital.com:80 ServerAlias ServerAdmin webmaster@hospital.com DirectoryIndex index.html index.htm index.php default.php app.php u.php ErrorLog logs/hospital.com-error.log CustomLog logs/hospital.com-access_%Y%m%d.log comonvhost <Directory "D:/UPUPW_AP5.5/vhosts/hospital.com/web"> Options FollowSymLinks AllowOverride All Require all granted </Directory> <LocationMatch "/(inc)/(.*)$"> Require all denied </LocationMatch> <LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$"> Require all denied </LocationMatch> </VirtualHost> //D:/UPUPW_AP5.5/vhosts/hospital.com/web WEB目录 //ServerName hospital.com:80 绑定的域名</code>
Configure VirtualHost
of apache
, take my project as an example:
Find the httpd.conf
of the server, and then configure the following content:
<code class="html"><VirtualHost *:80> ServerName admin.example.com ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ ErrorLog logs/admin.example.com-error_log CustomLog logs/admin.example.com-access_log common </VirtualHost> <VirtualHost *:80> ServerName www.demo.com ProxyPass / http://localhost:8081/ ProxyPassReverse / http://localhost:8081/ ErrorLog logs/demo.com-error_log CustomLog logs/demo.com-access_log common </VirtualHost></code>
The above configuration is to let apache
listen to port 80, which is the default port, and then when the user accesses admin.example.com
, it will distribute the request to the application on port 8080
. When a user accesses www.demo.com
, the request is distributed to the 8081
port. Of course, you need to configure as many VirtualHost
as you have programs. If you still don’t understand, you can search for apache port forwarding
, there are many tutorials.