我对 Apache vhost 感到困惑

发布于 2024-08-20 13:56:33 字数 790 浏览 11 评论 0原文

我正在使用 Zend Framework 构建一个 Web 应用程序,我需要将我的应用程序指向应用程序的“public”文件夹:

所以基本上当我调用 http://localhost/myapp 时 它应该显示 http://localhost/myapp/public/

我在 /etc/apache2/sites-available/ 中创建了一个名为 myapp 的虚拟主机文件:

    <VirtualHost *:80>
DocumentRoot /var/www/myapp/public/
 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /var/www/myapp/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
 </Directory>

</VirtualHost>

但它不起作用。当我调用 http://localhost/myapp 时,它会显示应用程序的目录结构,当我单击“public”文件夹,然后它显示我想要默认显示的内容...... 我以前从未配置过虚拟主机,这就是我从有关它的教程中获得的信息。

I am building a web application with Zend Framework, and I need to point my app to the "public" folder of the application:

So basically when I call http://localhost/myapp
it should display http://localhost/myapp/public/

I created a virtual host file called myapp into /etc/apache2/sites-available/:

    <VirtualHost *:80>
DocumentRoot /var/www/myapp/public/
 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /var/www/myapp/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
 </Directory>

</VirtualHost>

But it doesn't work. When I call http://localhost/myapp, it displays the directory structure of the app, and when I click on the "public" folder, then it displays what I want to be displayed by default...
I never configured vhosts before and that's as far as I got with the tutorials about it.

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

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

发布评论

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

评论(2

白色秋天 2024-08-27 13:56:33

在您的第一个列表中,您的 Directory 标签具有不同的值,完全省略了“public”。 DocRoot 值中的“public”后面还有一个尾部斜杠,但在第二次尝试时被删除。不确定这会产生什么影响,但我相信建议您不要包含尾部斜杠。

另外,只是想知道...您是否在本地计算机上运行它?如果我在 apache 服务器之前开始运行 Skype,我会遇到想要使用端口 80 的问题。如果 80 已被使用,Skype 将使用不同的端口。如果不是 Skype,则可能有其他应用程序正在使用端口 80 并产生干扰。这可能就是您在另一个端口取得成功的原因。

In your first listing, you had a different value for the Directory tag, leaving off 'public' altogether. There was also a trailing slash after 'public' in the DocRoot value, but removed on your second attempt. Not sure that made a difference, but I believe it's recommended that you don't include trailing slashes.

Also, just wondering...are you running this on a local machine? I had trouble with Skype wanting to use port 80 if I started running that before my apache server. Skype will use a different port if 80 is already used. If not Skype, there may be another app that's using port 80 and interfering. That could be why you had success on another port.

假扮的天使 2024-08-27 13:56:33

好吧,我找到了一种方法......我不认为这是必要的正确/最好的方法,但是......

在 httpd.conf (在 apache2 文件夹中):

Listen 10089

<VirtualHost *:10089>

    DocumentRoot "/var/www/myapp/public"

    <Directory "/var/www/myapp/public">

        Order allow,deny

        Allow from all

    AllowOverride all

</Directory>

</VirtualHost>

我的应用程序现在可以通过 localhost:10089 访问
在 apache 中启用重写模块后,我添加了必要的 .htaccess,它位于我的应用程序的根目录,将所有内容重定向到 index.php(Zend 框架支持友好的 url 导航并以这种方式工作):

RewriteEngine on

RewriteRule .* index.php

以及我的应用程序中的第二个 .htaccess 文件public 文件夹允许人们访问 .jpg、.ico 等文件,而不是被重定向到所有内容的索引:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ /index.php [NC,L]

希望这会对一些人有所帮助!

Ok I found a way somehow... I don't think it's necessary the right/best way but...

in httpd.conf (in apache2 folder):

Listen 10089

<VirtualHost *:10089>

    DocumentRoot "/var/www/myapp/public"

    <Directory "/var/www/myapp/public">

        Order allow,deny

        Allow from all

    AllowOverride all

</Directory>

</VirtualHost>

My app is now accessible via localhost:10089
After enabling the rewrite mod in apache, I added the necessary .htaccess, one at the root of my app, redirecting everything to index.php (Zend framework support friendly url navigation and works that way):

RewriteEngine on

RewriteRule .* index.php

and a second .htaccess file inside my public folder to allow people to access .jpg,.ico,etc files and not being redirected to index for everything:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ /index.php [NC,L]

Hope this will help some!

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