On Mon, Dec 18, 2023 at 2:51 AM Gestió Servidors
<sysadmin.c...@uab.cat.invalid> wrote:

> Hi,
>
>
>
> I define both vhost with <hostname>:<port> because each “hostname” links
> to different hosts. Machines A and B are differents and they are serving
> its sites, so in Apache I must declare (I think…) each host because I need
> to differentiate them. If I use *:<port>, how are I differentiating both
> hosts if they are different?
>
>
>
> Output of “apachectl -S”:
>
>    - in my running R (CentOS), where redirection works:
>
> VirtualHost configuration:
>
> my_ip_address:80     is a NameVirtualHost
>
>          default server A.mydomain (/etc/httpd/conf.d/000-default.conf:1)
>
>          port 80 namevhost A.mydomain
> (/etc/httpd/conf.d/000-default.conf:1)
>
>                  alias A
>
>                  alias A.mydomain.v2
>
>          port 80 namevhost B.mydomain
> (/etc/httpd/conf.d/000-default.conf:101)
>
>                  alias B
>
>                  alias B.mydomain.v2
>
> ServerRoot: "/etc/httpd"
>
> Main DocumentRoot: "/var/www/html"
>
> Main ErrorLog: "/etc/httpd/logs/error_log"
>
> Mutex mpm-accept: using_defaults
>
> Mutex authdigest-opaque: using_defaults
>
> Mutex proxy-balancer-shm: using_defaults
>
> Mutex rewrite-map: using_defaults
>
> Mutex authdigest-client: using_defaults
>
> Mutex proxy: using_defaults
>
> Mutex authn-socache: using_defaults
>
> Mutex default: dir="/run/httpd/" mechanism=default
>
> PidFile: "/run/httpd/httpd.pid"
>
> Define: _RH_HAS_HTTPPROTOCOLOPTIONS
>
> Define: DUMP_VHOSTS
>
> Define: DUMP_RUN_CFG
>
> User: name="apache" id=48
>
> Group: name="apache" id=48
>
>    - in my new R (Rocky-8.9), where redirection doesn’t work:
>
> VirtualHost configuration:
>
> 192.168.1.2:80         A.mydomain (/etc/httpd/conf.d/000-default.conf:1)
>
> 192.168.1.5:80         B.mydomain (/etc/httpd/conf.d/000-default.conf:101)
>
> ServerRoot: "/etc/httpd"
>
> Main DocumentRoot: "/var/www/html"
>
> Main ErrorLog: "/etc/httpd/logs/error_log"
>
> Mutex authdigest-opaque: using_defaults
>
> Mutex watchdog-callback: using_defaults
>
> Mutex proxy-balancer-shm: using_defaults
>
> Mutex rewrite-map: using_defaults
>
> Mutex authdigest-client: using_defaults
>
> Mutex lua-ivm-shm: using_defaults
>
> Mutex proxy: using_defaults
>
> Mutex authn-socache: using_defaults
>
> Mutex default: dir="/etc/httpd/run/" mechanism=default
>
> Mutex cache-socache: using_defaults
>
> PidFile: "/etc/httpd/run/httpd.pid"
>
> Define: DUMP_VHOSTS
>
> Define: DUMP_RUN_CFG
>
> User: name="apache" id=48
>
> Group: name="apache" id=48
>
>
>
> Thanks a lot!
>
>
>
> *De:* Frank Gingras <thu...@apache.org>
> *Enviat:* divendres, 15 de desembre de 2023 15:49
> *Per a:* users@httpd.apache.org
> *Tema:* Re: [users@httpd] Problems with "VirtualHost"
>
>
>
>
>
>
>
> On Fri, Dec 15, 2023 at 2:57 AM Gestió Servidors <
> sysadmin.c...@uab.cat.invalid> wrote:
>
> Hello,
>
>
>
> I have a small Apache where I run a redirection to two private hosts. My
> machine (R, router) is connected to Interned and to a private LAN
> (192.168.x.x/16). Behind “R”, there are two machines (A and B) that are
> serving two websites. R has an DNS alias with two public DNS names for A
> and B (because some years ago, A and B were machines with public IP
> addresses). Now, I want to change R and configure a new R machine (newest
> distribution). However, in new R, redirect doesn’t run and I can’t get
> browing from Internet to A and B websites. I copypaste here all information:
>
>
>
>    - R:
>
>
>    - CentOS-7.9.2009
>       - Apache: 2.4.6-99.el7.centos.1
>
>
>    - new R:
>
>
>    - Rocky Linux 8.9
>       - Apache: 2.4.37-62.module+el8.9.0+1436+2b7d5021
>
>
>
> My configuration file where I have configured “VirtualHost” is the same in
> both servers:
>
>
>
> <VirtualHost A.mydomain:80>
>
>         ServerAdmin foo@boo <sysadmin.c...@uab.cat>
>
>         ServerName A.mydomain
>
>         ServerAlias A A.mydomain
>
>         LogLevel info
>
>         ErrorLog /var/log/httpd/virtualhost-A.log
>
>         ProxyPass / http://192.168.1.2/
>
>         ProxyPassReverse / http://192.168.1.2/
>
>         <Location />
>
>                 <RequireAny>
>
>                         Require ip my_network
>
>                 </RequireAny>
>
>         </Location>
>
>
>
>         <Directory />
>
>                 Options FollowSymLinks
>
>                 AllowOverride None
>
>         </Directory>
>
>         <Directory /var/www/html/>
>
>                 Options Indexes FollowSymLinks MultiViews
>
>                 AllowOverride all
>
>                 <RequireAny>
>
>                         Require ip my_network
>
>                 </RequireAny>
>
>         </Directory>
>
> </VirtualHost>
>
>
>
> <VirtualHost B.mydomain:80>
>
>         ServerAdmin foo@boo <sysadmin.c...@uab.cat>
>
>         ServerName B.mydomain
>
>         ServerAlias B B.mydomain
>
>         LogLevel info
>
>         ErrorLog /var/log/httpd/virtualhost-B.log
>
>         ProxyPass / http://192.168.1.5/
>
>         ProxyPassReverse / http://192.168.1.5/
>
>         <Location />
>
>                 <RequireAny>
>
>                         Require ip my_network
>
>                 </RequireAny>
>
>         </Location>
>
>
>
>         <Directory />
>
>                 Options FollowSymLinks
>
>                 AllowOverride None
>
>         </Directory>
>
>         <Directory /var/www/html/>
>
>                 Options Indexes FollowSymLinks MultiViews
>
>                 AllowOverride all
>
>                 <RequireAny>
>
>                         Require ip my_domain
>
>                 </RequireAny>
>
>         </Directory>
>
> </VirtualHost>
>
>
>
> With this file, in server R, redirection runs perfectly and when I browse
> http://A/mysiteA, R redirect connection to private machine A (the same
> when I browse to http://B/mysiteB). However, in new R, when I browse to
> http://A/mysiteA (or http://B/mysiteB), there are no redirection and I
> can see at logs this message: File does not exist: /var/www/html/mysiteA
> (or  File does not exist: /var/www/html/mysiteB).
>
>
>
> Where is the problem?
>
>
>
> Thanks!
>
>
>
>
>
> You don't want to define a vhost as <hostname>:<port>, unless you know
> exactly what you are doing.  When unsure, always use *:<port>.
>
>
>
> Show the output from apachectl -S or httpd -S after you applied the fixes.
>

That's a mistake; use *:PORT and set an explicit ServerName in each vhost.

Then, show the new httpd -S / apachectl -S output, and the corrected
vhosts, and we can look at the redirects.

Reply via email to