2

I have a drupal app and 2 other app written in php, i want use a rewrite uri for drupal and place drupal in virtual root / and the other by their names ... and use the server cache for the img of each app.

ex :

  • xxx.com or xxx.com/ --> /var/www/xxx.com/drupal/
  • xxx.com/app1 or xxx.com/app1/ ----> /var/www/xxx.com/app1/
  • xxx.com/app2 or xxx.com/app2/ ----> /var/www/xxx.com/app2/

I have tested : alias, root in each location, conditional $request_uri, separate config ... and always one error : img path, php path, 404 for one of all app or drupal

so I'm really lost ...

here a test (maybe some good things) :

    # enforce www
if ($host !~* ^(www)) {
    rewrite ^/(.*)$ $scheme://www.$host/$1 permanent;
}

location / {
    root   /var/www/gplaza.cl/Drupal;
    index  index.php index.html;

    if (!-f $request_filename) {
        rewrite  ^(.*)$  /index.php?q=$1  last;
        break;
    }

    if (!-d $request_filename) {
        rewrite  ^(.*)$  /index.php?q=$1  last;
        break;
    }
}

location /app1/ {
    alias /var/www/gplaza.cl/app1/;   
    index index.php;
}

location /app2/ {
    alias /var/www/gplaza.cl/app2/;   
    index index.php;
}

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /var/www/xxx.com$fastcgi_script_name;
}

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {

    set $static_content /var/www/xxx.com/Drupal;

    if ($request_uri ~ ^/app1) {
        set $static_content /var/www/xxx.com/app1;
    }
    if ($request_uri ~ ^/app2) {
        set $static_content /var/www/gplaza.cl/app2;
    }

    expires     30d;
    access_log  off;
    root $static_content;
}
thank a lot if anybody can help me :)
1

The location directives are checked in a predefined order (http://wiki.nginx.org/HttpCoreModule#location). In your case, the regular expression for PHP files is anc cache management are consideres first, then the / location and (if / should not match) the /app1/ and /app2/ directives. As root will always match, /app1/ is never checked.

The solution is simpley: Put the /app1/ and /app2/ before the /-location directive and reload the nginx configuration.

BurninLeo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.