-1

I have a website that I have hosted in /var/www/html. I was able to access it using my.ip.add.res. Now I want to be able to access it from multiple ports. I mean all three URLs, my.ip.add.res:80, my.ip.add.res:8000 and my.ip.add.res:8950, in the browser should lead to the same website.

What I tried:

Step 1: In /etc/apache2/ports.conf file, Listen 80 was already there. I added Listen 8000 and Listen 8950. The file looks like:

Listen 80
Listen 8000
Listen 8950
<IfModule ssl_module>
        Listen 443
</IfModule>
<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

Step 2: In /etc/apache2/sites-available directory, there was a file 000-default.conf. I copied it to two files: myservice1.conf and myservice2.conf. I changed the first statement, VirtualHost *:80> to VirtualHost *:8000> and VirtualHost *:8950> in myservice1.conf and myservice2.conf files, respectively.

Step 3: I established symbolic links of these files to the corresponding files in /etc/apache2/sites-enabled. This is what I mean:

root@virtual-machine:/etc/apache2/sites-enabled# ls -l
total 0
lrwxrwxrwx 1 root root 35 Jul  7 09:18 000-default.conf -> ../sites-available/000-default.conf
lrwxrwxrwx 1 root root 46 Aug 22 11:45 loginservice.conf -> /etc/apache2/sites-available/loginservice.conf
lrwxrwxrwx 1 root root 44 Aug 22 11:44 scfservice.conf -> /etc/apache2/sites-available/scfservice.conf

Step 4: Then I restarted the Apache2 server

root@virtual-machine:/etc/apache2/sites-enabled# /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.

The result is:

my.ip.add.res : leads to correct website

my.ip.add.res:80 : leads to correct website

my.ip.add.res:8000 : Unable to Connect

my.ip.add.res:8950 : No such resource (even if I stop the server ... surprising)

What is it that I am doing wrong or missing?

Edit1: As suggested by jedifans, I tried apachectl -S. below is the output.

root@virtual-machine:/etc/apache2/sites-available# apachectl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80                   127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
*:8950                 127.0.1.1 (/etc/apache2/sites-enabled/loginservice.conf:1)
*:8000                 127.0.1.1 (/etc/apache2/sites-enabled/scfservice.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
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

Edit 2:

root@virtual-machine:/etc/apache2/sites-available# telnet 127.0.0.1 8000
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
root@virtual-machine:/etc/apache2/sites-available# telnet 127.0.0.1 8950
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

# gets stuck here. I have to ctrl + C to come out.
Sonu Mishra
  • 1,659
  • 4
  • 26
  • 45
  • Did you reload Apache? – jedifans Aug 22 '16 at 19:15
  • Yes, I restarted it. – Sonu Mishra Aug 22 '16 at 19:15
  • Any errors in the Apache error log? – jedifans Aug 22 '16 at 19:16
  • I can't see any log file. Do you have any idea where it can be? – Sonu Mishra Aug 22 '16 at 19:18
  • `/var/log/apache2/error.log` or `journalctl -xe`, try the first one and if nothing, check in the journal. – jedifans Aug 22 '16 at 19:19
  • I just checked. No, there is no error. – Sonu Mishra Aug 22 '16 at 19:25
  • What you have should work, assuming the main config includes the listed files/directories. Perhaps check the output of `apachectl -S` as noted in https://stackoverflow.com/questions/27152943/how-can-i-view-the-complete-httpd-configuration#27155469 – jedifans Aug 22 '16 at 19:34
  • An alternative problem might be that selinux or apparmour is blocking the port binding, or iptables is blocking access to those ports from localhost. – jedifans Aug 22 '16 at 19:36
  • I am not accessing it from `localhost`. It is on one of my company's local IP addresses. – Sonu Mishra Aug 22 '16 at 19:38
  • Also, as I added in my last edit, even if I stop the apache server, I get `no such resource` on 8950. – Sonu Mishra Aug 22 '16 at 19:39
  • 1
    Oh right. I have a feeling that a firewall is in play. Try running this on the server itself to see if Apache is the problem or not: `telnet 127.0.0.1 8000` and `telnet 127.0.0.1 8950`. If it connects, a service (most likely Apache) is running on those ports – jedifans Aug 22 '16 at 19:47
  • I tried both `apachectl -S` and `telnet` as you suggested. The outputs are mentioned in the two edits. I don't know how to find conclusions out of these. – Sonu Mishra Aug 22 '16 at 20:07
  • I just changed to 8001 and 8951, and everything is working fine. I wonder why 8000 and 8950 don't work! – Sonu Mishra Aug 22 '16 at 20:53
  • Check the output of `sudo netstat -nlp` to see what process is taking what port. There is also an `lsof` method but can't remember off the top of my head. – jedifans Aug 22 '16 at 21:14

2 Answers2

0
Listen 80
Listen 8000
Listen 8950

<VirtualHost *:80>
    ServerName www.example.com
    DocumentRoot "/var/www/html"
</VirtualHost>

<VirtualHost *:8000>
    ServerName www.example.com
    DocumentRoot "/var/www/html"
</VirtualHost>

<VirtualHost *:8950>
    ServerName www.example.org
    DocumentRoot "/var/www/html"
</VirtualHost>

Make sure to use Document root to /var/www/html and also if you are adding this line at end of http.conf then their is no need to add in two separate files if you wish to keep in two separate files see to it that you have a

Include sites-available/*.conf

The above Include is true if you have ServerRoot as /etc/apache2/ inn your case

However a simpler way would be just add above configuration to end of http.conf file

K patel
  • 54
  • 1
  • 5
0

The figured out what the problem was. All my steps were absolutely correct. However, there were already two services running on ports 8000 and 8950. I was able to get every port other than these two working.

Sonu Mishra
  • 1,659
  • 4
  • 26
  • 45