Thursday, December 7, 2017

debian - How to debug Apache2 virtual hosts

I'm hosting two websites in one server. Each has their own VirtualHost defined. First site works nicely but when I try to access the second I get redirected to the first one. It's like Apache would not recognize the correct VirtualHost by the ServerName and redirects me to the default (first) site.



Is there a log or something where I can see what steps Apache is taking when it handles my request? Does it log anywhere what ServerName it is using when it tries to find a matching VirtualHost?




Update:



I added a VirtualHost section for a subdomain of my second site and that works. It renders page from the correct application server that runs in 8501 port when I enter "interface.domain.com" into my browser. But when I try "www.domain.com" it redirects to my first site.



Below is my virtual host file for the second site.




ServerName www.domain.com
DocumentRoot /home/domain/current/public


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ http://localhost:8501/$1 [P]



ServerName interface.domain.com
DocumentRoot /home/domain/current/public


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ http://localhost:8501/$1 [P]



apache2ctl -S



AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 1.2.3.4. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:

1.2.3.4:443 www.domainfirst.com (/etc/apache2/sites-enabled/https_www_domainfirst_com.conf:1)
1.2.3.4:80 is a NameVirtualHost
default server domainfirst.com (/etc/apache2/sites-enabled/domainfirst_com.conf:1)
port 80 namevhost domainfirst.com (/etc/apache2/sites-enabled/domainfirst_com.conf:1)
port 80 namevhost www.domainfirst.com (/etc/apache2/sites-enabled/www_domainfirst_com.conf:1)
*:80 is a NameVirtualHost
default server domain.com (/etc/apache2/sites-enabled/domain_com.conf:1)
port 80 namevhost domain.com (/etc/apache2/sites-enabled/domain_com.conf:1)
port 80 namevhost www.domain.com (/etc/apache2/sites-enabled/www_domain_com.conf:1)
port 80 namevhost interface.domain.com (/etc/apache2/sites-enabled/www_domain_com.conf:10)

ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
PidFile: "/var/run/apache2/apache2.pid"

Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33


Solution:



Clear the browser cache. My browser had cached a rule to forward request to the other site.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...