trynacode trynacode - 3 months ago 19
Javascript Question

Change NGINX configuration to look for relative paths

I was wondering how I could get NGINX to look for files that are essentially out of the root value. This is how my nginx.conf looks like within server

server {
listen 80;
server_name localhost;
root /home/parallels/Downloads/nginx/rickshaw/examples;



location /all {
alias /home/parallels/Downloads/nginx/rickshaw/examples
try_files $uri $uri/ /sample.html /sample.htm;
}


#error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}


I have a HTML file in rickshaw/examples that is calling on a javascript file that is located in
/home/parallels/Downloads/nginx/rickshaw/javascript/charts.js
by going like
src="../javascript/charts.js
. I tried using alias but that didn't really help. Any idea on how I could change the configuration file so that it can pick up on a file in a different relative directory. I know I could just copy the file into the root path but I want to find out how I can configure NGINX so that it looks for relative paths.

Thank you, and let me know if you need any further information!

JAG JAG
Answer

try adding a static path

    location /javascript/ {
            alias /home/parallels/Downloads/nginx/rickshaw/javascript/;
            autoindex off;
    }

and access it src="/javascript/charts.js"

Comments