简体   繁体   中英

Apache vhost config on non-standard port - only the first vhost is ever served

I am trying to serve 2 sites via Apache (v2.4.7 on ubuntu 14.04 LTS) on a non-standard port (8787). This is to accommodate a proxy setup (I have nginx serving other sites on port 80 on the same dedicated server). I am pretty confident the proxy configuration is fine but the vhosts seem to not be getting respected at the level of Apache (ie when I hit port 8787 directly, which nginx is not touching). The set up I have is seemingly very straightforward and as follows:

<VirtualHost *:8787>
    ServerName site1.com
    ServerAlias www.site1.com;
    DocumentRoot "/var/www/site1.com"

    <Directory "/var/www/site1.com">
      AllowOverride All 
    </Directory>  
</VirtualHost>

And...

<VirtualHost *:8787>
  ServerName site2.com;
  ServerAlias www.site2.com;
  DocumentRoot "/var/www/site2.com"

  <Directory "/var/www/site2.com">
    AllowOverride All 
  </Directory>  
</VirtualHost>

I also have a "Listen 8787" line replacing the "Listen 80" line in my top level /etc/apache2/ports.conf file. This is the sum total of the custom configuration I have done. Both sites have been enabled with a2ensite and the 000-default vhost has been disabled. I double checked that this worked by looking at the symlinks in /etc/apache2/sites-enabled. I've restarted Apache several times (w/ sudo) and rebooted the whole machine several times. No matter what, when I hit http://site2.com:8787 (and also http://site1.com:8787 ) I am served site1.

I have looked around everywhere to try and surface the specific thing that might be causing this and I am completely out of ideas. If anybody has dealt with this please let me know and I will follow up with a status on the fix right away.

Updating this: I resolved the problem. It was actually the trailing semicolons on certain lines of the vhost conf which I'd accidentally inserted (I guess I'd been editing too many Nginx conf files). I think perhaps they were being treated as part of the hostname by Apache

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM