Tag Info

Hot answers tagged

7

This is the standard nginx behaviour for this part of your configuration : location /upload { if ($http_referer !~ "^http://(.+\.)?foo\.com/"){ rewrite .*\.(jpe?g|gif|bmp|png)$ /nohotlink.gif break; } location ~ \.(php|sql|php3|php4|phtml|pl|py|jsp|asp|htm|shtml|sh|cgi)$ { deny all; } } Why? Let me clarify how ...


5

You don't. The web server is allowed to decode percent-encoded characters which don't decode to special characters before applying rewrite rules, and is allowed to decode the remainder of percent-encoded characters before passing the data to your web application. (See RFC 3986.) What you should be doing is applying the front controller pattern in your web ...


4

There's an apache module called mod_substitute that can do this. Here's a short example: <Location "/"> AddOutputFilterByType SUBSTITUTE text/html Substitute "s/uat.site.co.jp/jp.uat.site2uk.co.uk/ni" </Location> Or, when combined with mod_proxy: ProxyPass / http://uat.site.co.jp/ ProxyPassReverse / http://uat.site.co.jp/ Substitute ...


4

In case you use nginx as a load-balancer, the stream will be : Redirect : Step 1 : Client => LB (HTTP request) Step 2 : LB => Client (HTTP reply) Step 3 : Client => Backend (HTTP request) Step 4 : Backend => Client (HTTP reply) Proxy : Step 1 : Client => LB (HTTP request) Step 2 : LB => Backend (HTTP request) ...


4

You have misunderstood the $request_filename variable. It represents the physical path mapped to the file considering root and alias directives values and the current URI being processed. So your error_page directive will internally redirect to a URI corresponding to a physical path that doesn't exist as it the same as the path tested to enter your if ...


3

Try this block for the public location: location /public { if ($args ~ "^pid=(?<placepid>[0-9]+)$") { rewrite ^/places /index.php?url=places/view/$placepid last; } if ($args ~ "^q=(?<getq>.+)&l=(?<getl>.+)$") { rewrite ^ /index.php?url=search/index/$getq/$getl last; } if ($args ~ ...


3

nginx always requires the leading slash in the URI part of the rewrite, while Apache doesn't want it. Without seeing the complete configuration, this is just a guess what the problem might be. Try this: rewrite ^/([^/]*)/([^/]*)\.html$ /?cmm=$1&page=$2 last;


3

With three rules you can match the example cases and following versions of the widgets: rewrite ^\/widget\/(v\d+)\/?(\?act=)?(.*)$ /widget/$1.php?act=$2 last; rewrite ^\/widget\/?$ /widget/index.php last; rewrite ^\/widget\/?(\?act=)?(.*) /widget/index.php?act=$2 last; I have written these using a online regexp tester but did not setup a test environment ...


3

Locations using regexs must use the operator ~ : location ~ ^/wp-(admin|login)\.php$ { return 444; } Read this part of the official documentation to understand how locations work and this other part to understand what's the processing order.


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 ...


3

First thing, ^~ usage is not necessary if you don't have any regex matching this pattern prior to the location your are defining. What you want to do is basically have proper URIs and rewrite them to pass an argument to your php application. In this case, the appropriate solution is using rewrites. The thing you missed in there is that the URI you are ...


3

If you haven't restarted Apache, be sure to do that, but if you've already done so, you could try a global output filter that runs a custom PHP script to do your replacing just to see if that solves it for some reason. EDIT: based on your comment, it could be that substitute isn't working because the content is compressed. To turn off compression, add ...


3

Ok, solution by myself: Add file with pcre: virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf, pcre:/etc/postfix/virtual_alias_maps.cf In file: /^admin@(.*)/ admin@$1,webmaster@$1 Reload, done.


3

This rewrite rule will do the trick: rewrite ^/something/(.+)$ http://domain.com/anything/$1 permanent;


3

You should not use redirect for post. If you have to, you should use 307 code for post. A end-user may be prompted about redirection. W3C Specifications - RFC 2616 301 Moved Permanently If the 301 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be ...


3

In nginx, you won't use a rewrite for this at all. You would use try_files instead. For example: try_files $uri $uri/ /puppy/index.php; Or, more likely, try_files along with a named location to handle PHP scripts. This isn't something that should be done in isolation; it is an integral part of the entire server block and you should not consider it ...


2

Unfortunately the only reasonable solution is to fix the application so that it generates correct URLs. All other solutions will cause subtle issues.


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+)$ ...


2

You should use another server block for the redirect. server { server_name *.domain.tld; listen 100.10.10.1; location /personal { rewrite ^ http://domain.tld/personal permanent; } } And then you should remove the location block from the other server block, and remove *.domain.tld from the server_name directive.


2

You need the break flag added to the rewrite rule, so that processing stops, and as this is inside a location block processing will continue inside that block: rewrite ^/petproject/?(.*)$ /$1 break; Note I also added /? to the matching pattern so that you don't end up with double slashes at the beginning of the url.


2

The configuration has the usual problem that generally happens with nginx. That is, using root directive inside location block. Try using this configuration instead of your current location blocks: root /home/me/Documents/site1; index index.html; location /petproject { alias /home/me/pet-Project/website; } This means that the default directory for ...


2

The problem shown by your error log indicates that your location /forum/... is not being matched. location /forum/(images|language|sounds|templates|uploads|vendor|src\/modules|nodebb\.min\.js(\.map)?|stylesheet\.css|admin\.css) { alias /srv/minora.me/webservices/forum.minora.me/public/; } The problem I see here is that this isn't treated ...


2

This should work: map $loc $loc_text { 11337 bar; 11419 restaurant; } map $style $style_text { 15477 painting; } rewrite ^/art/kartiny/location/(?P<loc>\d+)/style/(?P<style>\d+)$ /art/kartiny/location/$loc_text/style/$style_text redirect; See also http://nginx.org/en/docs/http/server_names.html#regex_names


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

The nginx documentation for rewrite (http://nginx.org/en/docs/http/ngx_http_rewrite_module.html) states that unless you end the replacement string with a '?' all previous qstring vars are appended. This means you don't need to (and probably shouldn't be) adding your qstring vars to the replacement. Also I would be as specific as I could be on the location ...


2

You were really close, but there are a couple of subtleties with S3 Routing Rules that you need to take into account: The HttpErrorCodeReturnedEquals element is one form of negative matching, but while an object that isn't present may cause a 404, it also may cause a 403. This depends on the bucket policy. You'll need to determine which is the case for ...


2

If i understood you currectly you need something like this: map $http_host $name { hostnames; p.test.tst.com.local test.com; ... } ... server { ... location / { fastcgi_pass unix:/var/run/php5-fpm.sock include fastcgi_params fastcgi_param HTTP_HOST $name; } This ...


2

If you want your site to answer to these Hosts values then you have no choice, you must put them in the server_name directive (you could use wildcard or regex to make the conf shorter). server { server_name www.test.com; include /path/to/server_names; [ ... ] location / { [ ... ] fastcgi_param HTTP_HOST "www.test.com"; ...


2

Wouldn't the error_page directive do this for you you? For example something like this: server { ... error_page 404 /404page.html; ... location = /authreq.html { if ($allowed = 0){ return 404; } } }


2

You can try Apache rewrite rules as below. RewriteEngine On RewriteCond %{REQUEST_URI} !(import\/batch_name1|import\/batch_name2|import\/batch_name3) [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA]



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