我有一个我在/var/www/html
中托管的网站。我能够使用my.ip.add.res
访问它。现在我想能够从多个端口访问它。我的意思是全部三个网址,my.ip.add.res:80
,my.ip.add.res:8000
和my.ip.add.res:8950
,在浏览器中应该导致同一个网站。如何使apache2上的服务响应多个端口上的请求
我试了一下:
步骤1:在/etc/apache2/ports.conf
文件,Listen 80
已经在那里了。我加了Listen 8000
和Listen 8950
。该文件看起来像:
Listen 80
Listen 8000
Listen 8950
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
步骤2:在/etc/apache2/sites-available
目录中,有一个文件000-default.conf
。我将它复制到两个文件:myservice1.conf
和myservice2.conf
。我将VirtualHost *:80>
的第一条语句分别更改为VirtualHost *:8000>
和VirtualHost *:8950>
,并将myservice1.conf
和myservice2.conf
文件分别更改为VirtualHost *:80>
。
第3步:我建立了这些文件到/etc/apache2/sites-enabled
中相应文件的符号链接。这就是我的意思是:
[email protected]:/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
步骤4:然后我重新启动的Apache2服务器
[email protected]:/etc/apache2/sites-enabled# /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.
结果是:
my.ip.add.res
:导致正确的网站
my.ip.add.res:80
:导致正确的网站
my.ip.add.res:8000
:无法连接
my.ip.add.res:8950
:没有这样的资源(即使我停止服务器......令人惊讶的)
它是什么,我做错了或丢失?编辑1:根据jedifans的建议,我试了apachectl -S
。下面是输出。
[email protected]:/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
编辑2:
[email protected]:/etc/apache2/sites-available# telnet 127.0.0.1 8000
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
[email protected]:/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.
你重新加载了Apache吗? – jedifans
是的,我重新启动它。 –
Apache错误日志中的任何错误? – jedifans