I'm using the official windows version of nginx. I want to specify the windows equivalent of this configuration
location /static/ {
alias /home/user/staticfiles/;
}
How do I specify windows file paths in the alias directive? Is this even possible?
These answers must be out of date. Using nginx 1.3.8 absolute paths with forward slashes works. Backslashes seem to work, but should be doubled. If they aren't then some, such as a trailing
\"
are taken literally.The quotes may not be required, but they seem like a good idea in case of embedded spaces.
One other thing I noticed is that it is important to match the url and alias path regarding ending with a trailing slash or not--a mismatch and it doesn't work.
If you try to specify an absolute path like...
...then upon requesting a file from that location, you'll probably see errors in C:\nginx\logs\error.log like:
When configuring nginx on Windows, specify any paths relative to the C:\nginx directory. This works:
Personally, I was happy to learn this because it makes my nginx configurations a little more portable between Windows and Linux than I had expected them to be. To turn a Linux configuration file into one that works on Windows, for me it's basically just:
For NGINX on Windows you have to use this method:
Where
foo
is an actual folder insidefolder2
.You can try this:
set into nginx.conf
location /static/ { alias /nginx/html/staticfiles/; }
seems that alias doesn't work at all for my windows system. I tried to type
but even this doesn't work. And I cannot find a way to output the location after the config file is reloaded by nginx. So simply do not use alias in windows for nginx.