我对 Apache vhost 感到困惑
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的第一个列表中,您的 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.
好吧,我找到了一种方法......我不认为这是必要的正确/最好的方法,但是......
在 httpd.conf (在 apache2 文件夹中):
我的应用程序现在可以通过 localhost:10089 访问
在 apache 中启用重写模块后,我添加了必要的 .htaccess,它位于我的应用程序的根目录,将所有内容重定向到 index.php(Zend 框架支持友好的 url 导航并以这种方式工作):
以及我的应用程序中的第二个 .htaccess 文件public 文件夹允许人们访问 .jpg、.ico 等文件,而不是被重定向到所有内容的索引:
希望这会对一些人有所帮助!
Ok I found a way somehow... I don't think it's necessary the right/best way but...
in httpd.conf (in apache2 folder):
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):
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:
Hope this will help some!