I installed apache on centos and added two virtual hosts (server1.com and server2.com ):
server1.conf
Listen 443 https
<VirtualHost *:443>
DocumentRoot /opt/server1/
ServerName server1.com
ServerAlias server1.com
<Directory "/opt/server1/">
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm-server1.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
server2.conf
<VirtualHost *:443>
DocumentRoot /opt/server2/
ServerName server2.com
ServerAlias server2.com
<Directory "/opt/server2/">
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm-server2.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
The configuration above works perfectly, I can access server1.com and server2.com both on port 443 on the browser and they show different contents (perfect).
Now the problem is that I want two instances of apache separate, so I can start and stop each instance when needed. I created two services in /etc/systemd/system folder.
- The problem is when I do systemctl start httpd-server1.service, server1.com works perfectly, but server2.com also works and shows same content as server1.com. Only server1.com should be working!!
- Second problem is when I do systemctl start httpd-server2.service, It fails and says "no listening sockets available, shutting down" and even if I add another "listen 443" on top of my server2.conf, I still get another error "could not bind to address [::]:443"
Here are the commands in the two systemctl service files that start the httpd processes:
/opt/httpd/sbin/apachectl -f /etc/opt/httpd/conf/httpd-server1.conf -k start
/opt/httpd/sbin/apachectl -f /etc/opt/httpd/conf/httpd-server2.conf -k start
httpd-server1.conf points to server1.conf and httpd-server2.conf to server2.conf so I don't get why when starting one service, the other cannot start as well even on the same port..
I am lost, and I don't know how to make each instance separately. Anyone has this issue before ?