2016-08-22 55 views
-1

我有一个我在/var/www/html中托管的网站。我能够使用my.ip.add.res访问它。现在我想能够从多个端口访问它。我的意思是全部三个网址,my.ip.add.res:80my.ip.add.res:8000my.ip.add.res:8950,在浏览器中应该导致同一个网站。如何使apache2上的服务响应多个端口上的请求

我试了一下:

步骤1:在/etc/apache2/ports.conf文件,Listen 80已经在那里了。我加了Listen 8000Listen 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.confmyservice2.conf。我将VirtualHost *:80>的第一条语句分别更改为VirtualHost *:8000>VirtualHost *:8950>,并将myservice1.confmyservice2.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. 
+0

你重新加载了Apache吗? – jedifans

+0

是的,我重新启动它。 –

+0

Apache错误日志中的任何错误? – jedifans

回答

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> 

确保使用文档根目录到/ var/www/html等,也如果你是在http.conf中的末尾添加这一行那么他们是没有必要在两个单独的文件添加如果你想保持在两个单独的文件看到它,你有一个

Include sites-available/*.conf

上面的包含是真实的,如果你有ServerRoot作为/ etc/apache2/inn你的情况

但是更简单的方法只是将上面的配置添加到http结尾。conf文件

+0

我已经有'Include sites-available/*。conf'和'Include sites-enabled/*。conf' int eh config文件。 –

+0

DocumentRoot也已设置 –

0

找出问题所在。我所有的步骤都是完全正确的。但是,已经有两个服务在端口8000和8950上运行。我能够获得除这两个端口以外的其他端口。

相关问题