Configure apache to listen on port other than 80

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?

475585 次浏览

在文本编辑器中打开 httpd.conf 文件。 Find this line:

Listen 80

然后改变它

Listen 8079

更改后,保存它并重新启动 apache。

是防火墙的问题。有一个硬件防火墙阻止了几乎所有端口的访问。(关闭软件防火墙/SELinux bla bla 没有效果)

然后我扫描了打开的端口,并使用了打开的端口。

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

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

它会扫描你系统上所有打开的端口。任何打开的端口都可以从外部访问。

参考文献 : < a href = “ http://www.go2linux.org/which _ service _ or _ program _ is _ listen _ on _ port”rel = “ norefrer”> http://www.go2linux.org/which_service_or_program_is_listening_on_port

/etc/apache2/ports.conf中,将端口更改为

Listen 8079

然后转到 /etc/apache2/sites-enabled/000-default.conf

并将第一行更改为

<VirtualHost *: 8079>

现在重启

sudo service apache2 restart

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

FC22服务器

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

改变: 听着80 致: Listen whatevernumber

保存文件

Systemctl 重新启动 httpd.service [ enter ] 如果需要,打开路由器/防火墙中的任何号码

This is working for me on Centos

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

Listen 8079

之后

Listen 80

直到您的服务器监听端口8079

第二: 转到虚拟主机寻找 ex. < strong >/etc/httpd/config.d/vhost.conf

并在下面添加此代码

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

这意味着当你转到你的 www.example.com:8079重定向到

/var/www/html/api _ file

但是首先需要重新启动服务

sudo service httpd restart

如果你使用 Windows 上的 Apache:

  1. 使用 Win + R + services.msc + Enter检查 Apache 服务的名称(如果它不是 ApacheX.Y,它应该有你在 Apache 中使用的软件的名称,例如: “ wampapache64”) ;
  2. 启动 命令提示符为 < strong > Administrator (使用 Win + R + cmd + Enter是不够的) ;
  3. 切换到 Apache 的目录,例如: 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. 确保服务已停止: httpd.exe -k stop -n "YourServiceName"
  6. httpd.exe -k start -n "YourServiceName"开始
  7. 如果一切开始顺利,问题就不复存在了,但如果你得到:

    AH00072: make _ sock: 无法绑定到地址 IP: PORT _ NUMBER

    AH00451: 没有监听插座可用,正在关闭

    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 不是记事本 - 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. 检查与 Win + R + resmon + Enter一起使用该端口的进程的 PID,单击 Network选项卡,然后单击 港口子选项卡;
  9. Kill it with: taskkill /pid NUMBER /f (/f forces it);
  10. 重新检查 resmon以确认端口现在是空闲的,然后重复步骤6。

This ensures that Apache's service was started properly, the configuration on 正如 sarul 提到的虚拟主机配置文件 (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".

如果你需要 apache 监听端口而不是80,你应该在 ubuntu 下添加下一个文件

”/etc/apache2/ports.conf“

监听端口列表

Listen 80
Listen 81
Listen 82

在您必须进入 Virtual hosts conf 文件并定义 next 之后

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




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




<VirtualHost *:82>
#...host 3
</VirtualHost>

如果启用了 ufw (非复杂防火墙) ,则运行此命令。 添加示例端口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