Can't change virtualhost listen port without crashing my site

July 21, 2014 3.5k views

Hi, I am trying to configure Varnish in an Ubuntu 14.04 server running three virtual hosts and I am getting stuck in the previous step of changing listen port in apache ports.conf and sites-available/site.conf.

It doesn't matter what port I try (recommended 8080, 8585, 4000, etc), after restarting the server I get a connection error when trying to visit my website.

Can you help me?

1 comment
  • What's the connection error you're getting? Are there any error messages in /var/log/apache2/error.log?

10 Answers

try checking apache error log for details

I don't see any error. Am I missing something?:

[Mon Jul 21 17:54:58.001140 2014] [:notice] [pid 1607] ModSecurity for Apache/2.7.7 (http://www.modsecurity.org/) configured.
[Mon Jul 21 17:54:58.001512 2014] [:notice] [pid 1607] ModSecurity: APR compiled version="1.5.1-dev"; loaded version="1.5.1-dev"
[Mon Jul 21 17:54:58.001529 2014] [:notice] [pid 1607] ModSecurity: PCRE compiled version="8.31 "; loaded version="8.31 2012-07-06"
[Mon Jul 21 17:54:58.001539 2014] [:notice] [pid 1607] ModSecurity: LUA compiled version="Lua 5.1"
[Mon Jul 21 17:54:58.001555 2014] [:notice] [pid 1607] ModSecurity: LIBXML compiled version="2.9.1"
[Mon Jul 21 17:54:59.010104 2014] [mpm_prefork:notice] [pid 1608] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.3 configured -- resuming normal operations
[Mon Jul 21 17:54:59.010203 2014] [core:notice] [pid 1608] AH00094: Command line: '/usr/sbin/apache2'

By the way, already tried to disable modsecurity and that didn't help.

  • Does Varnish output any errors?

    sudo grep -i varnish /var/log/messages
    sudo grep -i varnish /var/log/syslog

now how about that particular vhost error log?

Nothing there... no error is being recorded.

are u sure you enabled your vhost then?

I´m sorry, I missed some answers:

What's the connection error you're getting?
Connect to 188.226.XXX.XXX on port 80 ... failed
Error 111: Connection refused
Error while fetching URL

Not sure why it using port 80 since I have set the listen port to 8585 in ports.conf

Does Varnish output any errors?
Varnish is installed but not yet configured. I was just messing around with the apache listen port when I noticed the error.
And yes, Varnish seems to be logging another error:
varnishd[5535]: -T localhost:6082 Could not be resolved

are u sure you enabled your vhost then?
Yes, I am able to browse my site if i set the ports.config and virtalhost listen port back to 80. The problem is that I need to change it in order to activate Varnish. Am I wrong?

Your browser always uses port 80 unless you tell it otherwise, as in http://domain.com:8585

Varnish listens on port 80 and makes requests to your web server on the port you specify, such as 8585. Once you change the port in ports.conf, you should be able to browse your site using the port you specify (if it is open on your firewall). Once Varnish is in place and configured, you will be able to browse your site as usual without specifying a port number - Varnish will be completely transparent to you. (Pretty slick how they named that.)

Thanks, I didn't knew that. After changing ports to 8080 (8585 was not allowed) in in apache ports.conf and sites-available/site.conf I´m experiencing a strange behaviour:

site1.com:8080 returns a server error
site2.com:8080 returns site1.com

Why is that?


site1.com:8080 returns the site.
site2.com:8080 returns a 301 redirection to site2.com, which returns fetching error since tries to connect on port 80.

This was solved after configuring varnish. Thanks.

Have another answer? Share your knowledge.