Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a VM with several development apps living on it. The basic web directory looks like:

/var/web/subdoms/:
    index.php
    MyApp/
    SomeOtherApp/

I have my Nginx config file specifying the root as /var/web/subdoms, such that:

http://myserver/  -> /var/web/subdoms/index.php.

In the MyApp subdirectory, is a Symfony2 Project. In the SomeOtherApp directory is a generic perl-cgi app

http://myserver/SomeOtherApp  -> /var/web/subdoms/SomeOtherApp/index.pl

Requests to MyApp need to redirected to a subdirectory such that:

http://myserver/MyApp/    ->  /var/web/subdoms/MyApp/symfony/web/

From there, requests need to rewritten so that requests are delivered to 'app.php' ala:

http://myserver/MyApp/          -> /var/web/subdoms/MyApp/symfony/web/app.php
http://myserver/MyApp/hello/you -> /var/web/subdoms/MyApp/symfony/web/app.php/hello/you

I can accomplish this when i set my root: /var/web/subdoms/MyApp/symfony/web/ and request sans 'MyApp' by following the examples on the symfony documentations. However, when I try to nest the app one directory (so that my server can serve multiple apps on the same domain instead of being dominated by the symfony app), the "MyApp" part gets added to the url ala:

http://myserver.com/MyApp/hello/you  -> /var/web/subdoms/MyApp/symfony/web/app.php/MyApp/hello/you

And then symfony complains that it can't find the route "MyApp/hello/you". I could solve this by prepending 'MyApp' to all my symfony routes, but this feels clunky. I'd rather find a way through Nginx to forward the url sans directory to Symfony.

If it helps, here's my current nginx config (with the other apps removed):

server {
    listen          80;
    server_name myserver;

    root /var/web/subdoms;
    error_log /var/log/nginx/rr_error.log;
    access_log /var/log/nginx/rr_access.log;

    location /MyApp/ {
        rewrite ^/MyApp/(.*)$ /MyApp/symfony/web/app_dev.php/$1 last;
    }

    #was the way to redirect requests to app_dev.php when MyApp/Symfony/web was root
    location @rewriteRR {
        rewrite ^(.*)$ /app_dev.php/$1 last;
    }

    location ~ \.php(/|$) {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_pass 127.0.0.1:9000;
    }

    location ~ /\.ht {
        deny all;
    }

}

As a closing, i realize it's probably best to use a subdomain to seperate the apps (or multiple domains), but as previously stated, this is a development server. Splitting it among sub domains, different hosts, etc would be too costly for what it is. I need to keep it all on the same host/domain for cost reasons (SSL Certs/hosting fees) while avoiding self-signing my certs (because while development, the apps are used by other people in a casual context and the self signed errors irritate them).

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.