【问题标题】:apache2 not working for different portsapache2不适用于不同的端口
【发布时间】:2014-01-24 22:50:50
【问题描述】:

我希望能够在具有两个不同文档根目录的两个端口上运行 apache,一个带有 var/www 文件夹,另一个带有其他文件夹。以下是我在可用站点中的默认文件。但是每当我点击 127.0.0.1 时,第一个虚拟主机中的索引就会显示出来。 如果我点击 127.0.0.1:8080 url,我希望能够访问 /home/somefolder/tmp 中的索引,但我得到“浏览器无法连接到 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>

【问题讨论】:

    标签: apache apache2 virtualhost virtual-hosts


    【解决方案1】:

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

    Listen 8080
    

    NameVirtualHost *:8080
    

    在您的主要配置中设置,该配置因发行版而异。

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

    sudo netstat -ntlp | egrep 'apache|httpd'
    

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

    【讨论】:

    • 感谢这在我的机器上工作,但在远程机器上这没有工作。它给了我以下错误“你没有权限访问 / 在这个服务器上。”
    • 我在上面的 NameVirtualHost 上打错了字,现在更正为 8080。虽然您的错误听起来像是缺少默认文档或文档根目录不存在。检查您遇到问题的根目录的配置。
    • 您指的是什么默认文档?我的 docroot 确实存在
    • index.html 或您通过 DirectoryIndex 指令指定的任何内容。我建议你检查你的日志,看看 Apache 试图访问哪个目录。还要确保它具有读取目录的权限。
    【解决方案2】:

    试试这个,

    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。 :)

    【讨论】:

      猜你喜欢
      • 2014-01-29
      • 2014-10-21
      • 2013-11-09
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      • 1970-01-01
      相关资源
      最近更新 更多