0

I have two applications that I want to serve simultaneously under one domain in nginx.

Folder structure

/var/www/phm
    /client
        /static
            /css
              main.css
          index.html
    /server
        /public
           /img
               intro.png

nginx.conf

    server_name phm.example.com;
    
    root /var/www/phm;
    index index.html index.php;
    
    location / {
        try_files $uri /client/$uri @server;
    }
    
    location @server {
        try_files /server/public/$uri /server/public/index.php$is_args$args =404;
    }
    
    location ~ \.php {
        fastcgi_split_path_info ^/(.+\.php)(.*)$;
        include fastcgi.conf;
        internal;
    }

My expectation is, that the following requests are answered with the according files

  • phm.example.com ---> /var/www/phm/client/index.html
  • phm.example.com/static/css/main.css ---> /var/www/phm/client/static/css/main.css
  • phm.example.com/img/intro.png ---> /var/www/phm/server/public/img/intro.png
1

I would try a config like this:

server_name phm.example.com;

root /var/www/phm/client;
index index.html index.php;

location / {
    try_files $uri =404;
}

location /img {
    root /var/www/phm/server/public;

    try_files $uri /index.php$is_args$args;
}

location ~ \.php {
    fastcgi_split_path_info ^/(.+\.php)(.*)$;
    include fastcgi.conf;
}

In this config, the default is to serve files from /var/www/phm/client directory. For the location /img, the root directory is changed to /var/www/phm/server/public.

This configuration will serve http://phm.example.com/img/intro.png from /var/www/phm/server/public/img/intro.png.

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.