Niharika Upadhyay
Niharika Upadhyay

Reputation: 108

Configuring two symfony instances on one domain name

I have a development server where I have hosted a site which is build on symfony framework (www.example.com) Now for this domain name "www.example.com", we have all SSL certificates and other things required for the website.

I have a requirement where I have to deploy one more symfony instance but without creating a new domain name. How can I achieve it? Can it point to www.example.com/newInstance ?

Can I run two websites on a same domain name? www.example.com/oldInstance and www.example.com/newInstance

I have less knowledge about networking, so looking for help on this one.

Upvotes: 0

Views: 661

Answers (2)

Michael Sivolobov
Michael Sivolobov

Reputation: 13340

If you use Nginx + Apache and you want to point Apache to different directories according to path you can achieve it by using next configuration:

#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;
}

And set VirtualHost configuration for Apache:

#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>

If you have only Apache in your Configuration you can configure aliases as suggested by @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>

Also you can use your front-controller (e.g. app.php) to manage all traffic and import different files depending on Host name.

Upvotes: 1

Hokusai
Hokusai

Reputation: 2359

If you are using Apache as web server you can use alias to point each directory

<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>

If you request http://example.com/ you will get oldInstance directory. If you request http://example.com/newInstance you will get newInstance directory.

If you want get oldInstance directory by using http://example.com/oldInstance instead of http://example.com then you can configure another alias for that:

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

Remember to check if mod_alias is enabled in your Apache config.

LoadModule alias_module modules/mod_alias.so

I hope it helps you.

Upvotes: 2

Related Questions