apache2不适用于不同的端口

时间:2014-01-07 09:52:39

标签: apache apache2 virtualhost virtual-hosts

我希望能够在两个具有两个不同文档根的端口上运行apache,一个使用var / www文件夹,另一个使用其他文件夹.Below是我可用站点中的默认文件。但每当我点击127.0.0.1时,就会显示第一个虚拟主机中的索引。 我希望能够访问/ home / somefolder / tmp中的索引,如果我点击127.0.0.1:8080网址,但我得到“浏览器无法连接到127.0.0.1:8080”。我错过了什么?

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>
<VirtualHost *:8080>
    ServerAdmin webmaster@localhost

    DocumentRoot /home/somefolder/tmp
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

2 个答案:

答案 0 :(得分:3)

您需要确保Apache已设置为侦听端口8080,因此您需要

Listen 8080

NameVirtualHost *:8080

在主配置中设置,从发行版到发行版各不相同。

您可以使用以下命令检查Apache正在侦听的端口:

sudo netstat -ntlp | egrep 'apache|httpd'

听起来你会在那里看到80但不是8080。

答案 1 :(得分:0)

试试这个,

Listen 80
Listen 8080

NameVirtualHost 127.0.0.1:80
NameVirtualHost 127.0.0.1:8080

<VirtualHost 127.0.0.1:80>
#ServerName eightzero.com
DocumentRoot /var/www/
</VirtualHost>

<VirtualHost 127.0.0.1:8080>
#ServerName eightzeroeightzero.com
DocumentRoot /var/www-8080
</VirtualHost>

我希望这会对你有所帮助。尝试使用apache conf文件进行更改后,立即重新启动/重新加载httpd / apache2。 :)