Nginx rewrite rules

I am trying to implement nginx rewrite rules for the following situtation: - The request /testfa/styles/style.css should be redirected to /testfa/templates/styles/style.css I enabled the rewrite log entry for my server, created the following rules:

 location /testfa { rewrite ^/styles/(.+)?$ /testfa/templates/styles/$1 last; } 

but when I try to execute the request, I get a 404 error from the server, and the log file does not contain rewriting information, only the following message:

 open() "......../testfa/styles/style.css" failed (2: No such file or directory) 

What is the correct way to do such a rewrite for nginx ?

+4
source share
1 answer
 location /testfa/ { rewrite ^/testfa/styles/(.+)$ /testfa/templates/styles/$1 last; } 

Does this work for you?

my tested virtual>

 server { listen ...ip...:80; server_name sub.domain.com; root /usr/local/www/test; error_log /usr/local/www/test/error_debug.log debug; rewrite_log on; location /testfa/ { rewrite ^/testfa/styles/(.+)$ /testfa/templates/styles/$1 last; } } 

it works. even the magazine reported:

 2011/11/25 01:06:52 [notice] 35208#0: *456705 rewritten data: "/testfa/templates/styles/test.css", args: "", client: IP, server: sub.domain.com, request: "GET /testfa/styles/test.css HTTP/1.1", host: "sub.domain.com" 
+2
source

Source: https://habr.com/ru/post/1382975/


All Articles