一个服务器上的几个symfony项目具有相同的端口

时间:2017-10-14 12:37:02

标签: apache symfony

我在同一台服务器上安装两个项目时遇到问题。一些必要的信息:

  1. 一台VPS服务器
  2. 两个symfony项目(每个项目位于不同的目录中)
  3. 指向项目的子域名(first.domain.com / second.domain.com)
  4. 所有项目必须位于同一个端口(80)
  5. 我的服务器看起来像这样:

       Root directory: /var/www/html
         - index.php (welcome page)
         - projecta (first project)
         - projectb (second project)
    

    我想实现:

        domain.com -> index.php
        first.domain.com (domain.com/first) -> first project
        second.domain.com (domain.com/second) -> second project
    

    我的apache配置:

    Alias "/first" "/var/www/html/projecta/web"
    <VirtualHost *:80>
        ServerName vps.net
        ServerAlias http://vps.net/first
    
        DocumentRoot /var/www/html/projecta/web
        <Directory /var/www/html/projecta/web>
            AllowOverride None
            Order Allow,Deny
            Allow from All
    
            <IfModule mod_rewrite.c>
                Options -MultiViews
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^(.*)$ first/app.php [QSA]
            </IfModule>
        </Directory>
    
        ErrorLog /var/log/apache2/first_error.log
        CustomLog /var/log/apache2/first_access.log combined
    </VirtualHost>
    
    Alias "/second" "/var/www/html/projectb/web"
    <VirtualHost *:80>
        ServerName vps.net
        ServerAlias http://vps.net/second
    
        DocumentRoot /var/www/html/projectb/web
        <Directory /var/www/html/projectb/web>
            AllowOverride None
            Order Allow,Deny
            Allow from All
    
            <IfModule mod_rewrite.c>
                Options -MultiViews
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^(.*)$ projectb/app.php [QSA]
            </IfModule>
        </Directory>
    
        ErrorLog /var/log/apache2/second_error.log
        CustomLog /var/log/apache2/second_access.log combined
    </VirtualHost>
    

    我的问题是第一个项目覆盖第二个项目的路径(如果我更改第一个项目服务器,然后第二个工程)。

    现在看起来像:

    domain.com -> first project
    domain.com/first -> first project
    domain.com/second -> second project in web directory (when I click on the app.php then project run).
    

    解决

    以这种方式解决问题(仅在apache配置文件中,我不需要任何.htaccess文件)

    Alias "/first" "/var/www/html/projecta/web"
    <VirtualHost *:80>
        ServerName first.domain.com
        ServerAlias *.first.domain.com
    
        DocumentRoot /var/www/html/projecta/web
        <Directory /var/www/html/projecta/web>
            AllowOverride None
            Order Allow,Deny
            Allow from All
    
            <IfModule mod_rewrite.c>
                Options -MultiViews
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^(.*)$ first/app.php [QSA,L]
            </IfModule>
        </Directory>
    
        ErrorLog /var/log/apache2/first_error.log
        CustomLog /var/log/apache2/first_access.log combined
    </VirtualHost>
    
    Alias "/second" "/var/www/html/projectb/web"
    <VirtualHost *:80>
        ServerName second.domain.com
        ServerAlias *.second.domain.com
    
        DocumentRoot /var/www/html/projectb/web
        <Directory /var/www/html/projectb/web>
            AllowOverride None
            Order Allow,Deny
            Allow from All
    
            <IfModule mod_rewrite.c>
                Options -MultiViews
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^(.*)$ second/app.php [QSA]
            </IfModule>
        </Directory>
    
        ErrorLog /var/log/apache2/second_error.log
        CustomLog /var/log/apache2/second_access.log combined
    </VirtualHost>
    

    目前别名不起作用,但目前已经足够了。

0 个答案:

没有答案