0

Say I want to host different sites on different ports. The internal ip of the server is 192.168.1.108, the external ip is 170.24.180.160. And the ports 80, 81 and 82 of 170.24.180.160 have been forwarded by my router. Now I want to host site80, site81 and site82 in port 80, 81 and 82 individually, so if enter 170.24.180.160:82 will go to the site82.

I tried this:

Listen 80
Listen 81
...

NameVirtualHost 170.24.180.160:80
NameVirtualHost 170.24.180.160:81
...

<VirtualHost 170.24.180.160:80>
ServerName site80
DocumentRoot /home/yy/Sites/site80
</VirtualHost>

<VirtualHost 170.24.180.160:8080>
ServerName site81
DocumentRoot /home/yy/Sites/site81
</VirtualHost>
...

But it gives error:

*Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Wed Jun 27 16:10:25 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Wed Jun 27 16:10:25 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

My question is, based on the above schema, how to set up apache? Detailed example is much helpful. Thanks!

1
  • So... what have you tried? Jun 27, 2012 at 23:17

2 Answers 2

2

You either have two Listen 80 directives (which is making Apache try to listen on port 80 twice), or you have another webserver running on the machine. Check that there's nothing else listening on port 80:

netstat -tlnp | grep :80

If that doesn't display anything, remove the Listen 80 line from your configuration (it's probably already present in the default configuration).

2
  • Thanks,so netstat -tlnp | grep :80 returns nothing, by removing listen 80, I can start the apache with no error. However, when I enter 170.24.180.160:80, it gives a 404 error. I am sure the path in DocumentRoot is correct. Any thoughts? Thanks
    – cache
    Jun 27, 2012 at 23:38
  • 1
    @cache Check for other :80 VirtualHost blocks in the configuration. apache2ctl -S might be useful here.
    – mgorven
    Jun 27, 2012 at 23:40
2

Also you don't need NameVirtualHost if you are doing it by ports.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .