我有两个网站,我想用 Apache 在同一个 IP 上但不同的端口上运行它们。我修改了 ports.conf 文件,如下所示:
NameVirtualHost *:80
Listen 80
NameVirtualHost *:81
Listen 81
并且 sites-enabled 中的 000-default 文件如下:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName site-1.example.com
DocumentRoot /var/www/site/httpdocs/HTML/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/site/httpdocs/HTML>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<files xmlrpc.php>
order allow,deny
deny from all
</files>
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 *:81>
ServerAdmin webmaster@localhost
ServerName site-2.example.com
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
netstat 命令输出以下内容:
sudo netstat -tlpn | grep apache
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6492/apache2
tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 6492/apache2
每次我重新启动服务器时:
sudo service apache2 restart
关于防火墙,我尝试以下操作:
sudo ufw allow 81
和
sudo ufw disabe
不幸的是,当我在 80 端口运行我的服务器的 IP 时一切正常,但是当我在 81 端口运行 IP 时浏览器无法连接。
我还尝试在 80 端口运行第二个虚拟主机,一切正常。
我不明白我做错了什么。