我有以下服务器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; } }
我有以下链接的资源:
http://localhost:7777/standardlib/resources/css/standardlib.css
但是这个文件实际上在里面:
/standardlib/src/main/webapp/resources/css/standardlib.css
所以我试图重写url:
rewrite ^/standardlib/(.*)$ /standardlib/src/main/webapp/$1 last;
但由于某种原因,它不起作用。 我添加日志logging:
error_log logs/error.log notice; rewrite_log on;
但错误日志中没有关于重写的信息。
我用regex101检查了正则expression式,似乎正在捕获正确的组。
我究竟做错了什么?
UPDATE
它实际上工作,我已经添加了log_not_found on; ,但由于某种原因,它试图find以下文件:
`D:\webservers\nginx/html\standardlib\src\main\webapp\bootstrap.js`
代替
`D:\projects\gibr\standardlib\src\main\webapp\bootstrap.js`
这是我在日志中得到的:
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)
这是因为您正在将Windows根path与反斜杠混合在一起,并使用Unix样式的正斜杠。
在这里看到注释: 如何在nginx中指定Windows文件path
我不是Windows系统pipe理员,但似乎你需要使用像../这样的相对path来完成你的path和工作。
另请参阅: https : //www.ruby-forum.com/topic/172663