Score:0

Serve the same application files from both the root directory and subdirectory in Nginx

uz flag

We had an file drive application served by apache running on the following path:

https://app.example.com/app

We were required to update the app and change to use Nginx. We were also tasked to serve the application on:

https://app.example.com

However, we still have some files referencing the first path and we would like those paths to be accessible. For now, we can only serve files using the second path. My nginx configuration file is:

server {
    listen 80;
    listen [::]:80;
    
    server_name app.example.com;
    
    # Force HTTPS redirection
    return 301 https://$http_host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    
    server_name app.example.com;

    ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

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

    location ~ \.php(?:$|/) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        set $path_info $fastcgi_path_info;
        fastcgi_pass 127.0.0.1:9000;
    }
}

Given the configuration, I would love to serve both app.example.com and app.example.com/app with the same application files on the server. I tried using this:

location /app {
    rewrite ^/app(.*) /$1 last;
}

But it simply redirects all requests and I am unable to properly load a file for example with https://app.example.com/file?id=12345. I would appreciate any assistance in solving this. Thanks!

stark avatar
mu flag
Does this help? https://unix.stackexchange.com/q/157022/64699
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.