0

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.

  1. 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!!
  2. 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 ?

Greg Askew
  • 35,880
  • 5
  • 54
  • 82
  • Merge two config files and read apache docs about virtual hosts. You can't have two programs to listen on the same port in one machine. – Romeo Ninov Jun 28 '23 at 15:36
  • Thanks @RomeoNinov, If I merge them, I cannot start and stop them seperately, which I would like to achieve – el sparrow Jun 28 '23 at 15:38
  • You can change config of web sites and and make apache daemon to reload the configs w/o restart. Is this OK for you? – Romeo Ninov Jun 28 '23 at 15:40
  • @RomeoNinov I think I don't understance your answer. Are you talking about the graceful command option? It does not work since I cannot even start my service for server2. Do you know if it is possible to have two instances and start/stop them if needed ? – el sparrow Jun 28 '23 at 17:09
  • I see an example here https://serverfault.com/questions/31838/can-rhel-4-have-two-instances-of-apache-httpd-running-using-two-different-config , that is what I am trying to do but don't know why I am having ports issues. I can also see the notice " httpd-server1.service: Can't open PID file /var/opt/httpd-server1/run/httpd.pid" although instance of server 1 is working perfectly and the httpd.pid file can be found. I am wondering if the pid has to do with my issue – el sparrow Jun 28 '23 at 17:18
  • Merge the configs, virtual hosts, based on `ServerName`. And when you need to change one of the hosts use graceful reload of config (no restart) – Romeo Ninov Jun 28 '23 at 17:25
  • I think he want to use 2 container to separate the configuration. if one daemon fails, the other is not affected if I understood the point of view – djdomi Jun 28 '23 at 17:29
  • 1
    @djdomi exactly what I want!!! but it seems I can do that with what Romeo Ninov said? I don't know how if the reload would work, I will try and look into it. If you have any other suggestion, I will take it! Thanks everyone – el sparrow Jun 28 '23 at 17:36
  • well, you could either just use lxc/docker container to separate also the full stack – djdomi Jun 29 '23 at 17:52

0 Answers0