我希望能够在两个端口上运行 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/