如何配置 Apache 在同一域中拥有两个 symfony 项目(不使用子域)?
我正在尝试将 Apache 配置为在同一域下拥有不同的 symfony 项目(每个项目都有自己的框架安装),但我无法使用文件夹使其工作。
这就是我想要的:
- mydomain.com/projectone/
- mydomain.com/projecttwo/
我可以使用子域使其工作,但这不是我的首选解决方案,因为我最终拥有疯狂的子域,例如:
- projectone.mydomain .com
- backend.projectone.mydomain.com
- projecttwo.mydomain.com
- backend.projecttwo.mydomain.com
我在 Apache 中使用此配置以使其与子域一起使用:
<VirtualHost 127.0.0.1:8080>
ServerName projectone.mydomain.com
DocumentRoot "/home/projectone/web"
DirectoryIndex frontend.php
<Directory "/home/projectone/web">
Options -Indexes IncludesNOEXEC FollowSymLinks -MultiViews
AllowOverride None
Allow from All
RewriteEngine On
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ frontend.php [QSA,L]
</Directory>
Alias /sf /home/projectone/lib/vendor/symfony/data/web/sf
<Directory "/home/projectone/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
关于如何实现文件夹解决方案有什么想法吗?
提前致谢, 埃内科
I'm trying to configure Apache to have to different symfony projects (each with his own installation of the framework) under the same domain, but I can't get it to work using folders.
This is what I would like to have:
- mydomain.com/projectone/
- mydomain.com/projecttwo/
I can make it work using subdomains, but is not the preferred solution for me, because I end up having crazy subdomains like:
- projectone.mydomain.com
- backend.projectone.mydomain.com
- projecttwo.mydomain.com
- backend.projecttwo.mydomain.com
I'm using this configuration in Apache to make it work with subdomains:
<VirtualHost 127.0.0.1:8080>
ServerName projectone.mydomain.com
DocumentRoot "/home/projectone/web"
DirectoryIndex frontend.php
<Directory "/home/projectone/web">
Options -Indexes IncludesNOEXEC FollowSymLinks -MultiViews
AllowOverride None
Allow from All
RewriteEngine On
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ frontend.php [QSA,L]
</Directory>
Alias /sf /home/projectone/lib/vendor/symfony/data/web/sf
<Directory "/home/projectone/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Any idea on how to achieve the folders solution?
Thanks in advance,
Eneko
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我一直这样做。这是相关的 Apache 配置。我还设置了 每个 symfony 应用程序的自定义错误处理程序。
您还需要修改
web/.htaccess
文件中的这一行。I do this all the time. Here's the relevant Apache config. I also set up custom error handlers for each symfony app.
You also need to hack this line in your
web/.htaccess
file.我已经尝试过这段代码并且似乎有效。因为我还没有测试过它,所以我不确定这是否没有错误,但它可以给你一个提示。
I have tried this code and seems to work. Since I haven't tested it I am not sure about this being error free, but it can be a hint for you.
您可以在 ProjectConfiguration 中使用 setWebDir 方法来指定唯一的 Web在每个项目中提供服务的目录。这将允许您将项目文件(应用程序、配置、lib、插件等)托管在您想要的任何目录(/home/projectone)中,同时通常将 web/ 中的文件移动到完全不同的位置(/home/ mydomain/web/projectone)。您可以选择从
config/ProjectConfiguration.class.php
中的根 ProjectConfiguration 调整整个项目的 Web 目录:或者如果您希望每个应用程序都有不同的 Web 目录 (/projectone / 对于前端, /projectone/backend/ 对于后端)您可以在
apps/myapp/config/myappConfiguration.class.php
中的每个应用程序配置中设置 Web 目录:希望有帮助。
You can use the setWebDir method in your ProjectConfiguration to specify a unique web directory to serve out of in each project. This will allow you to host the project files (apps, config, lib, plugins, etc) in any directory you'd like (/home/projectone) while moving the files normally in web/ to a completely different location (/home/mydomain/web/projectone). You have the option of adjusting your entire project's web directory from your root ProjectConfiguration in
config/ProjectConfiguration.class.php
:or if you'd like each of your applications to have a different web directory (/projectone/ for the front-end and /projectone/backend/ for the back-end) you can set the web directory from each of the application configurations in
apps/myapp/config/myappConfiguration.class.php
:Hope that helps.
文档:https:// /symfony.com/doc/3.3/setup/web_server_configuration.html
Documentation: https://symfony.com/doc/3.3/setup/web_server_configuration.html