VirtualHost配置问题

时间:2015-07-30 18:10:59

标签: apache virtualhost wsgi mod-alias

我想在同一个ip主机上通过Apache端口80提供两个应用程序。为此,我定义了以下虚拟主机:

NameVirtualHost *:80

<VirtualHost *:80>

    DocumentRoot "/var/www/wsgi/rest_api"
    ServerName api

    WSGIDaemonProcess rest_api user=gms  threads=5
    WSGIScriptAlias /api /var/www/wsgi/rest_api/rest_api.wsgi
    WSGIPassAuthorization On


    <Directory /var/www/wsgi/rest_api/rest_api>
        Order deny,allow
        Allow from all
        Options  +Indexes
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "/var/www/extjs/cardiocatalogqt"
    ServerName cardiocatalogqt
    Alias /cardiocatalogqt /var/www/extjs/cardiocatalogqt
    <Directory /var/www/extjs/cardiocatalogqt>
        Options Indexes FollowSymLinks
        AllowOverride None
        Order Deny,Allow
        Allow from all
    </Directory>
</VirtualHost>

问题是只识别列表中的第一个(它们都独立工作)。我不想让这两个人一起工作,而不依赖于秩序?

修改

由于跨域(包括主机名和端口)的CORS身份验证问题,我试图避免使用不同的服务器名称。我想要的只是两个不同的路径,以便相应地解决:http://test.com/cardiocatalogqthttp://test.com/api

2 个答案:

答案 0 :(得分:1)

请创建两个具有不同服务器名称和不同文档根路径的不同虚拟主机

<VirtualHost *:80>
    ServerAdmin admin@test.com
    ServerName test.com
    ServerAlias www.test.com
    DocumentRoot /var/www/test.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

另外,将服务器名称添加到hosts文件中。

答案 1 :(得分:0)

mod_alias就是我想要的,ala http://httpd.apache.org/docs/2.2/mod/mod_alias.html

像魅力一样!

修改

更具体地说,我的配置如下所示:

WSGIDaemonProcess rest_api user=gms  threads=5
WSGIScriptAlias /api /var/www/wsgi/rest_api/rest_api.wsgi
WSGIPassAuthorization On

<Directory /var/www/wsgi/rest_api/rest_api>
    Order deny,allow
    Allow from all
    Options  +Indexes
</Directory>

<VirtualHost *:80>
    DocumentRoot "/var/www/extjs/cardiocatalogqt"
    ServerName cardiocatalogqt
    Alias /cardiocatalogqt /var/www/extjs/cardiocatalogqt
    <Directory /var/www/extjs/cardiocatalogqt>
        Options Indexes FollowSymLinks
        AllowOverride None
        Order Deny,Allow
        Allow from all
    </Directory>
</VirtualHost>