昨天搭建了apache2和subversion的环境,在内网访问时完全没有问题,但是如果从外网访问时,发现总是无法找到server打开网页。
查了很久,排除了各方面的原因后,判断是电信封掉了adsl上网的上行80端口,导致外部浏览器无法访问apache。
解决方法就是将apache的监听端口从80修改到8086即可。网络上的一些资料是基于旧的apache进行配置或者是windows环境下的apache,与ubuntu环境下的apache2的配置有些不同。下面的配置基于Ubuntu10.10以及apache2:
step1:修改监听端口以及主机端口为8086
<span style="font-family:Courier New;font-size:10px;">sudo vi /etc/apache2/ports.conf</span>
<span style="font-family:Courier New;font-size:10px;">NameVirtualHost *:8086 Listen 8086</span>
step2: 只要修改virtualHost的端口即可
<span style="font-family:Courier New;font-size:10px;">sudo vi /etc/apache2/sites-available/default </span>
<span style="font-family:Courier New;font-size:10px;"><VirtualHost *:8080></span>
root@u12d32:/etc/apache2/sites-available# cat default
<VirtualHost *:8086>
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>
root@u12d32:/etc/apache2/sites-available#
step3:重启apache2
<span style="font-family:Courier New;font-size:10px;">sudo service apache2 stop sudo service apache2 start</span>
<span style="font-family:Courier New;font-size:10px;"> </span>
<span style="font-family:Courier New;font-size:10px;">或者:</span>
<span style="font-family:Courier New;font-size:10px;">/etc/init.d/apache2 restart </span>