问题描述
我在设置 httpd.conf 或 .htaccess 文件以识别一台服务器上的多个 zend 框架站点时遇到问题.
I'm having trouble setting up my httpd.conf or .htaccess files to recognize multiple zend framework sites on one server.
对于开发,我只有一台服务器,我正在尝试设置站点,以便我可以像 localhost/app1、localhost/app2 等一样访问它们.
For development, I have just one server and I'm trying to setup the sites so I can access them like localhost/app1, localhost/app2, etc.
所以现在,当我转到 localhost/app1 时,它确实成功地重定向到了 localhost/app1/public/index.php,但是当我转到 localhost/app1/index/index 时,我得到了 404.
So right now, when I go to localhost/app1 it does successfully redirect to localhost/app1/public/index.php, however when I go to localhost/app1/index/index I get a 404.
这是我的虚拟主机文件:
Here is my vhosts file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/var/www"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/app1/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog logs/error.log
CustomLog logs/access.log common
</VirtualHost>
这是我来自/var/www/app1 目录的 .htaccess 文件:
and here is my .htaccess file from the /var/www/app1 directory:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ /app1/public/index.php [NC,R,L]
如果我将 vhosts 文件中的 DocumentRoot 行更改为 DocumentRoot "/var/www/app1/public"
然后 app1 可以正常工作,但我只能访问那个...在 http://localhost.这可能吗?我想要发生的是,如果/var/www 是文档根目录,那么如果我转到 localhost/app1,这些请求需要重定向到 localhost/app1/public/index.php,如果我转到 localhost/app2 那些请求需要重定向到 localhost/app2/public/index.php.
If I change the DocumentRoot line in the vhosts file to DocumentRoot "/var/www/app1/public"
then app1 does work correctly, but I can only access that one... at http://localhost. Is this possible? What I want to happen is if /var/www is the document root, then if I go to localhost/app1, those requests need to redirect to localhost/app1/public/index.php and if I go to localhost/app2 those requests need to redirect to localhost/app2/public/index.php.
我希望我解释清楚了,感谢您的帮助.
I hope I explained this clearly, any help is appreciated.
最后
我最喜欢 Phil 的解决方案,因为我不想更改本地主机文件并使用 ServerName 指令.如果您为每个应用程序拥有一个单独的域名,那么在生产环境中就可以了,但不能用于开发.
In the end
I liked Phil's solution best because I didn't want to have to change my local hosts file and use the ServerName directive. It would be fine in a production environment if you own a separate domain name for each app, but not for development.
除此之外,我在使用备用目录提供 Web 内容时遇到了 403 禁止问题.正如我所说,权限似乎是正确的,问题出在 SE_Linux 上,文件的安全上下文没有设置为 httpd_sys_content_t.我正在发布我在此处找到的解决方案,如它专门处理这个问题.谢谢.
In addition to that, I was having a 403 forbidden problem when using an alternate directory for serving up web content. As I stated, the perms seemed correct the problem was with SE_Linux, and the security context of the files not being set to httpd_sys_content_t. I'm posting that solution that i found here, as it deals specifically with the issue. Thanks.
推荐答案
这就是我要做的...
在文档根目录之外的任意位置安装您的应用程序,例如
/home/sudol/apps/app1
和/home/sudol/apps/app2
.确保您的 Apache 用户可以遍历此路径并读取文件.
Install your applications somewhere arbitrary but outside the document root, eg
/home/sudol/apps/app1
and/home/sudol/apps/app2
. Make sure your Apache user can traverse this path and read the files.
为 部分中的
public
目录设置别名
Alias the public
directories in your <VirtualHost>
section
Alias /app1 /home/sudol/apps/app1/public
Alias /app2 /home/sudol/apps/app2/public
在适当的<Directory>
部分(每个应用一个)中设置您的访问和重写规则,例如
Setup your access and rewrite rules in the appropriate <Directory>
sections (one for each app), eg
<Directory "/home/sudol/apps/app1/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /app1
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</Directory>
删除 .htaccess
文件,因为您不再需要它们
Delete the .htaccess
files as you will no longer need them
附录
确保在应用程序配置中设置唯一的会话名称.您还可以设置特定的 cookie 路径,但这是可选的,例如
Addendum
Make sure you set unique session names in your application config. You can also set specific cookie paths but this is optional, eg
; app1/application/configs/application.ini
resources.session.name = "app1"
resources.session.cookie_path = "/app1/"
; app2/application/configs/application.ini
resources.session.name = "app2"
resources.session.cookie_path = "/app2/"
这篇关于一台服务器上的多个 Zend 框架站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!