在一个域名上配置两个 symfony 实例

Configuring two symfony instances on one domain name

我有一个开发服务器,我在其中托管了一个基于 symfony 框架构建的站点 (www.example.com) 现在对于这个域名 "www.example.com",我们拥有网站所需的所有 SSL 证书和其他东西。

我有一个要求,我必须再部署一个 symfony 实例,但不能创建新域名。我怎样才能实现它? 它可以指向 www.example.com/newInstance 吗?

我可以 运行 同一个域名上的两个网站吗? www.example.com/oldInstance 和 www.example.com/newInstance

我对网络的了解较少,因此寻求这方面的帮助。

如果您使用 Apache 作为 Web 服务器,您可以使用 alias 指向每个目录

<VirtualHost *:80>
  DocumentRoot "path/To/Your/DocumentRoot/oldInstance"
  ServerName www.example.com

  <Directory "path/To/Your/DocumentRoot/oldInstance">
    DirectoryIndex app.php
    Options Indexes    
    AllowOverride All
    Require all granted
  </Directory>

   Alias /newInstance "path/To/Your/DocumentRoot/newInstance"

   <Directory "path/To/Your/DocumentRoot/newInstance">
      DirectoryIndex app.php
      Options Indexes
      AllowOverride All
      Require all granted
  </Directory>  
</VirtualHost>

如果您请求 http://example.com/ you will get oldInstance directory. If you request http://example.com/newInstance 您将获得新的实例目录。

如果你想使用 http://example.com/oldInstance instead of http://example.com 获取 oldInstance 目录,那么你可以为其配置另一个别名:

Alias /oldInstance "path/To/Your/DocumentRoot/oldInstance"

记得检查您的 Apache 配置中是否启用了 mod_alias

LoadModule alias_module modules/mod_alias.so

希望对你有所帮助

如果你使用Nginx + Apache,并且你想根据路径将Apache指向不同的目录,你可以使用下一个配置来实现:

#Nginx
location /newInstance {        
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host YOUR_HOST_FOR_APACHE_HERE;
    proxy_pass http://127.0.0.1:8080;
}

location /oldInstance {        
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host ANOTHER_HOST_FOR_APACHE_HERE;
    proxy_pass http://127.0.0.1:8080;
}

并为 Apache 设置 VirtualHost 配置:

#Apache
<VirtualHost *:8080>
    DocumentRoot    "/var/www/newInstance"
    ServerName      YOUR_HOST_FOR_APACHE_HERE
</VirtualHost>

<VirtualHost *:8080>
    DocumentRoot    "/var/www/oldInstance"
    ServerName      ANOTHER_HOST_FOR_APACHE_HERE
</VirtualHost>

如果您的配置中只有 Apache,您可以按照@Hokusai 的建议配置别名:

<VirtualHost *:80>
  DocumentRoot "path/To/Your/DocumentRoot/oldInstance"
  ServerName www.example.com

  <Directory "path/To/Your/DocumentRoot/oldInstance">
    DirectoryIndex app.php
    Options Indexes    
    AllowOverride All
    Require all granted
  </Directory>

   Alias /newInstance "path/To/Your/DocumentRoot/newInstance"

   <Directory "path/To/Your/DocumentRoot/newInstance">
      DirectoryIndex app.php
      Options Indexes
      AllowOverride All
      Require all granted
  </Directory>  
</VirtualHost>

您也可以使用前端控制器(例如 app.php)来管理所有流量并根据主机名导入不同的文件。