【问题标题】:Apache Virtual Host URLApache 虚拟主机 URL
【发布时间】:2011-03-25 03:08:12
【问题描述】:

我为一个运行良好的 Web 应用程序创建了一个 Apache 虚拟主机,但我的 URL 有问题。我希望只能使用类似于http://ip_address/app_name 的 url 访问我的应用程序,但现在也可以使用 http://ip_address/ 访问该应用程序。

我的虚拟主机如下所示:

NameVirtualHost 192.168.5.235:80

<VirtualHost 192.168.5.235:80>
  ServerName 192.168.5.235
  Alias /ksw "/home/ksw/site"
  DocumentRoot "/home/ksw/site/"
  ErrorLog /home/ksw/logs/error_log
  CustomLog /home/ksw/logs/access_log combined
</VirtualHost>

有没有办法将我的应用程序配置为只能使用http://ip_adress/app_name 访问?谢谢。

home /home/ksw/site 文件是:

drwxrwxr-x 18 apache apache   4096 Aug  4 17:41 .
drwxr-xr-x  4 root   root     4096 Aug  3 20:17 ..
-rw-rw-r--  1 apache apache    825 Aug  3 20:18 AdminSettings.sample
-rw-rw-r--  1 apache apache   2179 Aug  3 20:18 api.php
-rw-rw-r--  1 apache apache     28 Aug  3 20:18 api.php5
drwxrwxr-x  2 apache apache   4096 Aug  3 20:17 bin
drwxrwxr-x  2 apache apache   4096 Aug  3 20:18 config
-rw-rw-r--  1 apache apache   4505 Aug  3 20:18 config.php
-rw-rw-r--  1 apache apache  17997 Aug  3 20:17 COPYING
drwxrwxr-x  4 apache apache   4096 Aug  3 20:18 docs
drwxrwxr-x  3 apache apache   4096 Aug  3 20:17 extensions
-rw-rw-r--  1 apache apache    162 Aug  3 20:18 FAQ
-rw-rw-r--  1 apache apache 236945 Aug  3 20:17 HISTORY
drwxrwxr-x  2 apache apache   4096 Aug  3 20:18 home
drwxrwxrwx  3 apache apache   4096 Aug  3 20:17 images
-rw-rw-r--  1 apache apache   2474 Aug  3 20:18 img_auth.php
-rw-rw-r--  1 apache apache     35 Aug  3 20:17 img_auth.php5
drwxrwxr-x  9 apache apache  12288 Aug  4 14:13 includes
-rw-rw-r--  1 apache apache   4561 Aug  3 21:03 index.php
-rw-rw-r--  1 apache apache     32 Aug  3 20:17 index.php5
-rw-rw-r--  1 apache apache   3992 Aug  3 20:17 INSTALL
-rw-rw-r--  1 apache apache   3772 Aug  3 20:18 install-utils.inc
drwxrwxr-x  4 apache apache   4096 Aug  3 20:18 languages
drwxrwxr-x  2 apache apache   4096 Aug  3 20:17 locale
-rw-rw-r--  1 apache apache   4993 Aug  4 14:05 LocalSettings.php
drwxrwxr-x  8 apache apache   4096 Aug  3 20:18 maintenance
-rw-rw-r--  1 apache apache    569 Aug  3 20:18 Makefile
drwxrwxr-x  2 apache apache   4096 Aug  3 20:17 math
-rw-rw-r--  1 apache apache   1532 Aug  3 20:18 opensearch_desc.php
-rw-rw-r--  1 apache apache   6173 Aug  3 20:18 profileinfo.php
-rw-rw-r--  1 apache apache   3535 Aug  3 20:18 README
-rw-rw-r--  1 apache apache    299 Aug  4 17:41 redirect.php
-rw-rw-r--  1 apache apache     35 Aug  3 20:17 redirect.php5
-rw-rw-r--  1 apache apache     91 Aug  3 20:17 redirect.phtml
-rw-rw-r--  1 apache apache  34280 Aug  3 20:17 RELEASE-NOTES
drwxrwxr-x  2 apache apache   4096 Aug  3 20:17 serialized
-rw-rw-r--  1 apache apache  18814 Aug  3 20:18 setup.php
-rw-rw-r--  1 apache apache  20480 Aug  3 20:18 .setup.php.swp
drwxrwxr-x  9 apache apache   4096 Aug  3 20:18 skins
-rw-rw-r--  1 apache apache    603 Aug  3 20:18 StartProfiler.php
drwxrwxr-x  4 apache apache   4096 Aug  3 20:17 t
-rw-rw-r--  1 apache apache  12822 Aug  3 20:18 Test.php
drwxrwxr-x  2 apache apache   4096 Aug  3 20:18 tests
-rw-rw-r--  1 apache apache   2746 Aug  3 20:18 thumb.php
-rw-rw-r--  1 apache apache     32 Aug  3 20:18 thumb.php5
-rw-rw-r--  1 apache apache   1373 Aug  3 20:18 trackback.php
-rw-rw-r--  1 apache apache  13195 Aug  3 20:18 UPGRADE
drwxrwxr-x 16 apache apache   4096 Aug  3 20:18 wiki
-rw-rw-r--  1 apache apache     88 Aug  3 20:17 wiki.phtml
-rw-rw-r--  1 apache apache   3830 Aug  3 20:18 xmlp4.php

【问题讨论】:

    标签: apache apache2 virtualhost


    【解决方案1】:

    Captain Obvious 说不应该这样。 =)
    可能仅当“app_name”目录是指向“ip_addr”目录的符号链接时。
    或者,如果您使用 django(例如)并错误地配置了视图。
    你用php吗?如果是这样 - 肯定会发生错误=)


    补充:
    如果你的 'app_name' 字符串实际上是 'ksw' 比...
    您已经在站点根目录中安装了您的 mediawiki,并且只添加了一个“别名 /ksw”的链接!!
    解决方案:

    • 如果您只想限制对 http://ip_address/ 的访问,请使用 .htaccess apache 文件。
    • 如果您希望在 / 和 /app_name 有 2 个不同的页面,您需要创建文件夹“app_name”并在那里安装您的应用!

    就是这样。

    【讨论】:

    • 是的,我使用 php。它实际上是 MediaWiki 的一个版本,我试图让它发挥作用。
    • 站点根目录 (/home/ksw/site/) 中有哪些文件?请列出“ls -la”。我认为的主要问题=)......你有什么而不​​是'app_name'?那是“ksw”吗?
    • 是的,app_name 是 'ksw'。我用列表更新了我的问题。谢谢。
    猜你喜欢
    • 2011-06-19
    • 1970-01-01
    • 2019-08-25
    • 2012-04-26
    • 2012-09-25
    • 2018-06-26
    • 1970-01-01
    • 2011-05-04
    • 2011-11-04
    相关资源
    最近更新 更多