Apache 虚拟主机 URL

发布于 2024-09-12 09:36:11 字数 3580 浏览 5 评论 0原文

我为 Web 应用程序制作了一个 Apache 虚拟主机,运行良好,但 URL 存在问题。我希望仅使用类似于 http://ip_address/app_name 的 url 访问我的应用程序,但现在也可以使用 < a href="http://ip_address/">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/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

I made an Apache virtual host for a web application that works fine, but I have a problem with the URL. I want my application to be accessed only using an url similar with: http://ip_address/app_name, but now the aplication can be access also with http://ip_address/.

My virtual host looks like this:

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>

Is there a way to configure my application to be accessed only using http://ip_adress/app_name? Thanks.

The home /home/ksw/site files are:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

檐上三寸雪 2024-09-19 09:36:11

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


添加:
如果你的“app_name”字符串实际上是“ksw”,那么...
您已将 mediawiki 安装在站点根目录中,并且仅通过“别名/ksw”添加了一个链接!
解决方案:

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

就这样。

Captain Obvious says it shouldn't be so. =)
May be only if 'app_name' dir is a symbolic link to 'ip_addr' dir.
Or if you use django (for example) and configured views incorrectly.
Do you use php? If so - something definitely wrong happens=)


added:
If you 'app_name' string is actually 'ksw' than...
You've installed you mediawiki in the site root dir and ONLY added a link by 'Alias /ksw' to it!!
Solutions:

  • If you want ONLY to restrict access to http://ip_address/ use .htaccess apache file.
  • If you want 2 different pages at / and /app_name you need to create folder 'app_name' and install your app there!

That's all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文