apache2 不适用于不同端口

标签 apache apache2 virtualhost virtual-hosts

我希望能够在两个端口上运行 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 设置为监听端口 8080,因此您需要

Listen 8080

NameVirtualHost *:8080

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

您可以使用以下命令检查 Apache 正在监听哪些端口:

sudo netstat -ntlp | egrep 'apache|httpd'

听起来您会在那里看到 80,但看不到 8080。

关于apache2 不适用于不同端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20968518/

相关文章:

php - 通过 PHP Apache 和 Mysql 优化优化 Drupal

python - 如何在 Flask 中使用 SSL

apache - 如何在 OS X/Terminal 中设置 root 的文件权限?

Apache URL 重写问题

java - apache poi如何刷新整个工作簿

django - 我把 "WSGIPassAuthorization On"放在哪里?

apache2 - Apache 2.4.6 的新站点配置文件

java - 在 Java 中使用 Apache POI 读取上标 excel 文本

apache - "OR".htaccess mod_rewrite 中的标志

phpmyadmin - php 7.4 中缺少 mbstring 扩展