Tag Info

Hot answers tagged

3

location / is never used The problem you have is related to location precedence (emphasis added). nginx first searches for the most specific prefix location given by literal strings regardless of the listed order. [...] Then nginx checks locations given by regular expression in the order listed in the configuration file. The first matching expression ...


2

See here for the same issue in Apache - there, I recommended using an external program to handle the rewrite, since it's clunky to do it in native configuration. For nginx, the best approach might be to embed some perl in your configuration via ngx_http_perl_module - use perl_set to set a variable to a UTF-8-ified version of $r->uri, using the Encoding ...


2

Reading nginx's documentation and the PCRE library documentation can help you understand how rewrite and regex work. For your example you would need a location block wrapping two rewrite rules like this : location /browse { rewrite ^/browse/(\d+)$ http://serverA.mycompany.com/show_item.cgi?$1 [flag]; rewrite ^/browse/([A-Z]{2,4}-\d+)$ ...


1

If you make sure that the nginx default server contains your rewrite rule, you don't really need to specify the names at all as the server will react with the default server if an unknown name is requested. You can even define an explicit catch all server like so: server { listen 80 default_server; server_name _; rewrite ...


1

You can combine these 2 rules. I think these rules are located in a VHost config file or another config file, but not in .htaccess, nor in a Directory section inside the VHost config. This means you are in a per server context. The problem: In per server context, the substitution (last part of the rewrite) can be a file system path or an URL. Apache tries ...


1

Yes, either a proxy_pass or rewrite rule would work for that.


1

^/author/(*)$ means that it starts with /author/. The URLs you want to rewrite don't start with /author/. You need something like this: rewrite ^/.*/author/(.*)$ http://example.com/profile/$1 last; But I think this is better and probably more robust: rewrite /author/([^/]+)/?$ http://example.com/profile/$1 last;



Only top voted, non community-wiki answers of a minimum length are eligible