简体   繁体   中英

Can't access virtualhost on CentOS 6 with apache 2.2.15

I have been looking around and trying different configurations on httpd.conf file of apache 2.2.15 server but I could not find a solution to my problem. So I am posting it here to get some help from a Guru.

I have this configuration on my /etc/httpd/conf/httpd.conf on CentOS 6.7 server.

Listen 80
Listen 8080

<VirtualHost *:8080>
       ServerName example.com       (Corrected after the comment)
       DocumentRoot /var/www/dbgui       
       ErrorLog logs/dbgui-8080-error_log
       <Directory /var/www/dbgui>
              AllowOverride All
       </Directory>
</VirtualHost>

<VirtualHost *:80>
       ServerName example.com
       DocumentRoot /var/www/laravel/public
       ErrorLog logs/example-80-error_log
      <Directory /var/www/laravel>
              AllowOverride All
      </Directory>
</VirtualHost>

When I browse to http://example.com I get Laravel page (as expected) but when I browse to http://example.com:8080 I get "the connection has time out" .

I have already opened the port for 8080 on the IP tables

output of netstat -nltup
tcp        0      0 :::8080    :::*    LISTEN      13097/httpd
tcp        0      0 :::80      :::*    LISTEN      13097/httpd

and

Output of iptables -L -nv
0   0     ACCEPT  tcp  --  *  *  0.0.0.0/0     0.0.0.0/0      tcp dpt:8080
669 41648 ACCEPT  tcp  --  *  *  0.0.0.0/0     0.0.0.0/0      tcp dpt:80

I don't see anything in the logs. Although it seems apache is listening on port 8080, nothing gets through and logged for port 8080.

Any suggestion to resolve this problem?

The port is not supposed to be part of the ServerName directive.

Please remove the port from the ServerName directive like this:

<VirtualHost *:8080>
 ServerName example.com 
 DocumentRoot /var/www/dbgui 
 ErrorLog logs/dbgui-8080-error_log     
 <Directory /var/www/dbgui>
  AllowOverride All 
 </Directory> 
</VirtualHost>

See the examples on apache.org for reference

您应该检查NameVirtualHost参数,以确保可以从IP /端口组合中猜出虚拟主机

Thanks guys for your help. After a lot of research and trying different things and just before throwing a chair, I finally resolved it. Here it is: After making sure iptables has correct opened ports and protocol for tcp/8080 Next, double check the VirtualHost setup is correct and the above setup is correct. Next thing I did was made sure selinux is not blocking port 8080 by either disable it all together or set it to permissive mode.

#semanage port -l | grep http
http_cache_port_t              tcp      3128, 8080, 8118, 8123, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989

As it can be seen, port 8080 is listed in http_cache_port_t and now make sure selinux does not block that

#setsebool -P httpd_can_network_memcache 1

then list it to make sure, it sets to "on" or "1"

# getsebool httpd_can_network_memcache

none of the above commands did not resolve the problem, while I was investigating the logs /var/log/audit/audit.log and /var/log/httpd/access_log and /var/log/httpd/error_log I could not find anything wrong related to port 8080 After all that, I started thinking that it does not make sense because everything configured correctly but I cannot get through. So I just took a second look at iptables output:

#iptables -L -nv
0     0  ACCEPT    tcp  --  *     *    0.0.0.0/0   0.0.0.0/0    tcp dpt:8080
25  1316 ACCEPT    tcp  --  *     *    0.0.0.0/0   0.0.0.0/0    tcp dpt:80
24  1240 ACCEPT    tcp  --  *     *    0.0.0.0/0   0.0.0.0/0    tcp dpt:443

Which shows 0 packet and 0 bytes came through the server. I found this site

http://www.yougetsignal.com/tools/open-ports/

It showed the port 8080 is blocked. While holding the chair in the air as the last resort :), I contacted ISP and I was told there is firewall in front of the server and port 8080 is blocked and when they opened it, I put the chair down because I finally got access.

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