Configure apache to listen on port other than 80
Asked Answered
M

8

121

I use centOS server. I want to configure apache to listen on port 8079. I added LISTEN 8079 directive in httpd.conf.
I opened port 8079 in iptables and restarted iptables. I even stopped iptables service.

"netstat -nal | grep 8079" shows "tcp  0 0 :::8079 :::* LISTEN"

If I try to access http://localhost:8079 or http://myserver.com:8079 from that machine, I can access that page. BUT from any other machine I am not able to access the site on any port other than 80. On port 80, it works. On port 8079 it does not.

What else do I need to configure?

Medico answered 15/10, 2010 at 9:15 Comment(0)
M
24

It was a firewall issue. There was a hardware firewall that was blocking access to almost all ports. (Turning off software firewall / SELinux bla bla had no effect)

Then I scanned the open ports and used the port that was open.

If you are facing the same problem, Run the following command

sudo nmap -T Aggressive -A -v 127.0.0.1 -p 1-65000

It will scan for all the open ports on your system. Any port that is open can be accessed from outside.

Ref.: http://www.go2linux.org/which_service_or_program_is_listening_on_port

Medico answered 20/10, 2010 at 13:11 Comment(2)
netstat -anp | grep apache2 (You could see the listening port and PID from this if it's running.Ubuntu)Canticle
My cloud service provider had a firewall on top that was blocking the port. Check firewalls placed other than in the target server.Bimonthly
V
169

In /etc/apache2/ports.conf, change the port as

Listen 8079

Then go to /etc/apache2/sites-enabled/000-default.conf

And change the first line as

<VirtualHost *: 8079>

Now restart

sudo service apache2 restart

Apache will now listen on port 8079 and redirect to /var/www/html

Vevine answered 26/9, 2014 at 16:53 Comment(3)
No, just the "This webpage is not available" annoying message. Just to clarify, port 80 works perfectly. Changing both the VirtualHost and the Listen doesn't solve it for me. (AWS ubuntu). B.T.W the reason I need it to listen to a different port is because I've also configured nginx to listen to 80.Stodgy
quick question: did you open up the inbound port in the security groups as you say you're on AWS ubuntu ?Vevine
if there is line NameVirtualHost *:80 above Listen 80 do change that as well ......Broomcorn
T
82

Open httpd.conf file in your text editor. Find this line:

Listen 80

and change it

Listen 8079

After change, save it and restart apache.

Threefold answered 15/10, 2010 at 9:18 Comment(9)
yes, but I mentioned in the first line that I have already tried this "I added LISTEN 8079 directive in httpd.conf" :((Medico
Oh sory. I didnt see it. Can you post httpd.conf file any where? And are you using 3rd party software Wamp,Xampp,Appserv?Threefold
you can get httpd.conf here fileuploading.net/860467 nothing like WAMP, Xampp, Appserv. All I have done is compiling apache, tomcat and jk connector from source and trying my best to make them work together.Medico
i didnt find the problem :( everything seems normally. i tried add Listen 8076 line in my local server but its worked normally. Can you try re-setup apache if is possible?Threefold
as I said, on localhost it's working on my pc also. anyway, thanks for your answer. i only want to setup communication between apache and tomcat and for that probably apache runnning on port 80 is enough. i am still learning about it.Medico
ismailperim, yeah I use xampp. But its not started as of now. There is no IIS installed too, and no service listening on port 80. Any suggestions ? I also uninstalled and reinstalled Apache. Edit : Got it. I had modified my httpd.conf file to configure SVN server.(step 7 os this manual: willperone.net/Code/svnserver.php)Poppyhead
where is the httpd.conf file located? in my /etc/apache2 folder there is a apache2.conf file - is this the same as the httpd file? Because there are many such configuration files in this folder. any advice would be much appreciatedGenus
One thing everybody seems to forget when answering this kind of questions is to mention the file location. The file is located in /etc/apache2/ports.confJasonjasper
@Threefold I can able to change the port number from 80 to 8070 by changing as you said, and it is able to run on the 8070 port. But after few days the port number gets changed to 80 automatically. How do I stop it?Allege
M
24

It was a firewall issue. There was a hardware firewall that was blocking access to almost all ports. (Turning off software firewall / SELinux bla bla had no effect)

Then I scanned the open ports and used the port that was open.

If you are facing the same problem, Run the following command

sudo nmap -T Aggressive -A -v 127.0.0.1 -p 1-65000

It will scan for all the open ports on your system. Any port that is open can be accessed from outside.

Ref.: http://www.go2linux.org/which_service_or_program_is_listening_on_port

Medico answered 20/10, 2010 at 13:11 Comment(2)
netstat -anp | grep apache2 (You could see the listening port and PID from this if it's running.Ubuntu)Canticle
My cloud service provider had a firewall on top that was blocking the port. Check firewalls placed other than in the target server.Bimonthly
R
22

If you need apache Listen port other than 80, you should add next file under ubuntu

"/etc/apache2/ports.conf"

the list of Listen ports

Listen 80
Listen 81
Listen 82

After you have to go on your Virtual hosts conf file and define next

<VirtualHost *:80>
  #...v host 1
</VirtualHost>


<VirtualHost *:81>
  #...host 2
</VirtualHost>


<VirtualHost *:82>
  #...host 3
</VirtualHost>
Rattlehead answered 27/3, 2018 at 12:21 Comment(0)
G
10

This is working for me on Centos

First: in file /etc/httpd/conf/httpd.conf

add

Listen 8079 

after

Listen 80

This till your server to listen to the port 8079

Second: go to your virtual host for ex. /etc/httpd/conf.d/vhost.conf

and add this code below

<VirtualHost *:8079>
   DocumentRoot /var/www/html/api_folder
   ServerName example.com
   ServerAlias www.example.com
   ServerAdmin [email protected]
   ErrorLog logs/www.example.com-error_log
   CustomLog logs/www.example.com-access_log common
</VirtualHost>

This mean when you go to your www.example.com:8079 redirect to

/var/www/html/api_folder

But you need first to restart the service

sudo service httpd restart

Gobbler answered 30/12, 2015 at 20:42 Comment(0)
T
3

If you are using Apache on Windows:

  1. Check the name of the Apache service with Win+R+services.msc+Enter (if it's not ApacheX.Y, it should have the name of the software you are using with apache, e.g.: "wampapache64");
  2. Start a command prompt as Administrator (using Win+R+cmd+Enter is not enough);
  3. Change to Apache's directory, e.g.: cd c:\wamp\bin\apache\apache2.4.9\bin;
  4. Check if the config file is OK with: httpd.exe -n "YourServiceName" -t (replace the service name by the one you found on step 1);
  5. Make sure that the service is stopped: httpd.exe -k stop -n "YourServiceName"
  6. Start it with: httpd.exe -k start -n "YourServiceName"
  7. If it starts alright, the problem is no longer there, but if you get:

    AH00072: make_sock: could not bind to address IP:PORT_NUMBER

    AH00451: no listening sockets available, shutting down

    If the port number is not the one you wanted to use, then open the Apache config file (e.g. C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf open with a code editor or wordpad, but not notepad - it does not read new lines properly) and replace the number on the line that starts with Listen with the number of the port you want, save it and repeat step 6. If it is the one you wanted to use, then continue:

  8. Check the PID of the process that is using that port with Win+R+resmon+Enter, click on Network tab and then on Ports subtab;
  9. Kill it with: taskkill /pid NUMBER /f (/f forces it);
  10. Recheck resmon to confirm that the port is free now and repeat step 6.

This ensures that Apache's service was started properly, the configuration on virtual hosts config file as sarul mentioned (e.g.: C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf) is necessary if you are setting your files path in there and changing the port as well. If you change it again, remember to restart the service: httpd.exe -k restart -n "YourServiceName".

Trueman answered 4/2, 2016 at 18:36 Comment(0)
S
1

For FC22 server

cd /etc/httpd/conf edit httpd.conf [enter]

Change: Listen 80 to: Listen whatevernumber

Save the file

systemctl restart httpd.service [enter] if required, open whatevernumber in your router / firewall

Subjectivism answered 23/8, 2015 at 7:18 Comment(0)
A
1

Run this command if your ufw(Uncomplicatd Firewall) is enabled . Add for Example port 8080

$ sudo ufw allow 8080/tcp

And you can check the status by running

$ sudo ufw status

For more info check : https://linuxhint.com/ubuntu_allow_port_firewall

Accountancy answered 26/8, 2020 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.