I have the following server configuration:
server {
listen 7777;
server_name localhost;
rewrite ^/standardlib/(.*)$ /standardlib/src/main/webapp/$1 last;
location / {
root D:\Projects\gibr;
index index.html index.htm;
}
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://172.22.90.61:8008;
}
}
I have the following link for the resource:
http://localhost:7777/standardlib/resources/css/standardlib.css
But the file is actually inside:
/standardlib/src/main/webapp/resources/css/standardlib.css
So I'm trying to rewrite the url:
rewrite ^/standardlib/(.*)$ /standardlib/src/main/webapp/$1 last;
But for some reason it doesn't work. I added logging:
error_log logs/error.log notice;
rewrite_log on;
But there's no information in the error log about rewriting.
I've checked the regex with regex101, and seems to be capturing the correct group.
What am I doing wrong?
UPDATE
It's actually working, I've added log_not_found on;
, but for some reason it tries to find the following file:
`D:\webservers\nginx/html\standardlib\src\main\webapp\bootstrap.js`
instead of
`D:\projects\gibr\standardlib\src\main\webapp\bootstrap.js`
Here is what I've got in the log:
15128#7720: *1 "^/standardlib/(.*)$" matches "/standardlib/bootstrap.js"
15128#7720: *1 rewritten data: "\standardlib\src\main\webapp\bootstrap.js"
15128#7720: *1 CreateFile() "D:\webservers\nginx/html\standardlib\src\main\webapp\bootstrap.js" failed (3: The system cannot find the path specified)
It's because you are mixing a Windows root path with backslashes, with Unix style forward slahes.
See comments here: How do I specify Windows file paths in nginx
I'm no Windows sysadmin, but it seems you need to use relative paths like ../ to get your path complete and working.
Also see: https://www.ruby-forum.com/topic/172663