nginx location exception

Discussion in 'Server Operation' started by RicochetPeter, Mar 13, 2025.

  1. RicochetPeter

    RicochetPeter Member

    Hi gents,
    this might be a more general question, and to some might even seem trivial, but here it goes:
    Running a Perfect setup with nginx+ISPConfig just fine, I'm also hosting a domain where only a single app resides, and it has this optional directive:

    Code:
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    I would like to look at the web stats for this web, which is normally found in /stats/. But the URL is taken by the directive, handed to the app and it returns a 500.

    Q: How do I either change the directive to "exclude" the path /stats, or get around this in a different way, maybe by adding an additional "location" directive for /stats, but what does it have to look like?
     
  2. remkoh

    remkoh Active Member HowtoForge Supporter

    An exclude option doesn't exist.
    You should look into the order of / and /stats
    That's where your solution is.
    If I'm not mistaking /stats should be before /

    If your IPSC's vhost master file doesn't let you putting it in the right order use Nginx Directives on your website's Options tab in ISPC.
    Start with
    Code:
    location / { ##delete##
    }
    
    location /stats/ { ##delete##
    }
    
    and add the original /stats and your / config in the right order (just copy /stats config from your website's original vhost file)
    Code:
    location /stats/ {
        index index.html index.php;
        auth_basic "Members Only";
        auth_basic_user_file /var/www/clients/client2/web36/web//stats/.htpasswd_stats;
        add_header Content-Security-Policy "default-src * 'self' 'unsafe-inline' 'unsafe-eval' data:;";
    }
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
     
  3. RicochetPeter

    RicochetPeter Member

    thx, remkoh.
    in the end, I had to do what is described here.
    I also described the problem incorrectly, but I found that only after digging into it more: a few months ago, upon installation I modified the vhost file to point to the "public" directory as the Document root. Now, I removed that, did what the linked post says, and voilà: stats work now.

    Hints:
    freescout
    Laravel
    nginx
    public
    subdirectory
     
    remkoh likes this.

Share This Page