我有一台运行 Ubuntu 的虚拟机。我想在浏览器中输入“http://localhost/mwiki“并查看我的 MediaWiki 站点。我将此站点放入 /var/www/mwiki 文件夹并配置了 Apache“默认”文件。但是当我尝试在浏览器中打开此站点时 - 打开了以下网页:“在此服务器 Apache/2.2.11 (Ubuntu) mod_python/3.3.1 Python/2.6.2 Server at localhost Port 80 上未找到请求的 URL /mwiki/”。
此服务器上还运行着另一个网站(ReviewBoard 系统)。它运行完美。当我输入“localhost/reviews”时,我得到了这个网站的索引页。我对配置 Apache 的了解很少。
请帮忙。
/etc/apache2/sites-available/default
:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/var/www/mwiki"
AddDefaultCharset UTF-8
<Location "/mwiki">
Order allow,deny
Deny from all
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/var/www/reviews.mysite.com/htdocs"
AddDefaultCharset UTF-8
# Error handlers
ErrorDocument 500 /errordocs/500.html
# Serve django pages
<Location "/reviews/">
PythonPath "['/var/www/reviews.mysite.com/conf'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE reviewboard.settings
SetEnv PYTHON_EGG_CACHE "/var/www/reviews.mysite.com/tmp/egg_cache"
SetEnv HOME "/var/www/reviews.mysite.com/data"
SetHandler mod_python
PythonHandler django.core.handlers.modpython
PythonAutoReload Off
PythonDebug Off
# Used to run multiple mod_python sites in the same apache
PythonInterpreter reviewboard_reviews_mysite_com
</Location>
<Location "/reviews/media">
SetHandler None
</Location>
# Serve static media without running it through mod_python
# (overrides the above)
<Location "/reviews/errordocs">
SetHandler None
</Location>
<Directory "/var/www/reviews.mysite.com/htdocs">
AllowOverride All
</Directory>
# Alias static media requests to filesystem
Alias /reviews/media "/var/www/reviews.mysite.com/htdocs/media"
Alias /reviews/errordocs "/var/www/reviews.mysite.com/htdocs/errordocs"
</VirtualHost>
<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 /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/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>
答案1
你对工作原理有误解<VirtualHost >
。使用基于名称的虚拟主机(即,同一个 IP,多个主机名以区分它们)时,你需要有唯一的ServerName
s。
此外,您已将 wiki 设置DocumentRoot
为显示/var/www/mwiki
原因http://localhost/
。由于您只有一个 ServerName ( localhost
),我建议您添加一个Alias
而不是虚拟主机。
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/var/www/reviews.mysite.com/htdocs"
AddDefaultCharset UTF-8
Alias /mywiki /var/www/mwiki
# ...
虚拟主机仅当您有多个 IP 或主机名时才有用。示例:
# Use ServerNames to distinct virtual hosts on 127.0.0.1
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName site1.example.com
DocumentRoot /var/www/site1.example.com
</VirtualHost>
<VirtualHost 127.0.0.1:80>
ServerName site2.example.com
DocumentRoot /var/www/site2.example.com
</VirtualHost>
<VirtualHost 127.0.0.2:80>
ServerName meh.example.com
DocumentRoot /var/www/meh.example.com
</VirtualHost>
添加到/etc/hosts
:
127.0.0.1 site1.example.com
127.0.0.1 site2.example.com
# note: the next line is not included in the vhost config
127.0.0.1 invalid.example.com
127.0.0.2 meh.example.com
现在,您可以使用 {site1,site2,meh}.example.com 域访问主机。如果您打开 127.0.0.1 或,将选择invalid.example.com
第一个 vhost ( )。site1.example.com