0

I'm having trouble figuring out the basic syntax for proxying most traffic to a local Solr install but leaving one path/dir requests being sent to a static html directory. Do all secondary, tertiary, etc... locations need to be set by regex? Haven't been able to find a simple guide on this.

current errors: /adv/index.html - 404 - Not found /adv/ - 403 Forbidden /solr/ - works fine

Here is my config:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
#include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 1024;
        multi_accept on;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        index index.html;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        server {
                listen 80;

                location / {
                    proxy_pass http://localhost:8983;
                }

                location /adv/ {
                        # also wasn't sure what permissions needed here
                        # recursively set adv folder and files within to 777
                        alias /var/www/adv;
                }
        }
}
Tyndall
  • 591
  • 1
  • 7
  • 18
  • Check the error log, but also try `root /var/www;` instead of `alias /var/www/adv;` – Richard Smith May 12 '22 at 16:18
  • 1
    @Tyndall When you use an `alias` directive inside the location, you need to use slashes carefully. Your configuration will replace the `/adv/` prefix of your URI with the `/var/www/adv` resulting in invalid filename. [Here](https://stackoverflow.com/a/69296739/7121513) is more detailed explanation with examples. – Ivan Shatsky May 12 '22 at 16:38
  • weird. based off the logs its seems that my requests were either trying to get to /adv/adv/index.html when I used root and /advindex.html when I used alias. – Tyndall May 12 '22 at 16:45
  • If I try to use root and remove the adv from the path (letting it add itself from the url I pass) it works for everything except /adv, almost like it doesn't know its a directory and to just serve my index.html file. (/adv/ works and /adv/index.html works) – Tyndall May 12 '22 at 16:47
  • 1
    @Tyndall This is an expected behavior. You can force a redirect using something like `location = /adv { return 301 /adv/; }`. Use either `root /var/www` or `alias /var/www/adv/` inside the `location /adv/ { ... }`, but not the `alias /var/www/adv`. Using `root /var/www/` won't do such a harm since it will result in a `/var/www//adv/index.html` file path which would work too. – Ivan Shatsky May 12 '22 at 16:53
  • 1
    @Tyndall Or you can use either `location /adv { root /var/www; }` or `location /adv { alias /var/www/adv; }`, however it will overtake any request URI starting with `/adv`, e.g. `/advance`, too. – Ivan Shatsky May 12 '22 at 16:55
  • thanks everyone. So the solution that seems to be working for me. Is from Ivan's first comment (and Richard) is alias with no slashes on location path or alias path. Weird thing is ... when I type in /adv without the slash I think I'm getting redirected to a version of the url with the ending slash. Is that normal for Nginx to do this? – Tyndall May 12 '22 at 16:56
  • 1
    @Tyndall I think it is normal for every web server since `adv` is a directory and not a file. You are viewing an index inside the `adv` directory. Think of it like it is a filesystem. – Ivan Shatsky May 12 '22 at 16:59
  • Should add this as an answer to get credit. Thanks again. – Tyndall May 23 '22 at 14:49

0 Answers0