Tag Info

Hot answers tagged

7

First, you shouldn't use rootdirective inside the location block, it is a bad practice. In this case it doesn't matter though. Try adding a second location block: location ~ /some/path/(?<section>.*)/index.html { proxy_pass http://192.168.1.24/$section/index.html; proxy_set_header Host $host; } This captures the part after /some/path/ and ...


5

You should use URI part in proxy_pass directive. Also, you mixed up order arguments of proxy_redirect directive, and probably you don't need it at all. Nginx has reasonable default for this directive. In this case your location block could be really simple: location /some/path/ { proxy_pass http://192.168.1.24/; # note this slash -----------^ ...


5

I believe that this website may help you greatly: http://regex101.com/r/uP4nT1


5

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


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

As per http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule:- What is matched? In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html"). Your pattern is matching an exact URL of "docs". The actual URL is probably ...


3

You can't match on a query string at all in a rewrite. So you'll need to check the argument directly. For instance: if ($arg_discount ~ ^free) { rewrite ^/join_trial /test2? permanent; } rewrite ^/join_trial /test? permanent; And I suspect you really do not want to be sending 301 redirects, as the user will then see /test or /test2 right in their ...


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

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

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.


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]


2

I think what you want is Alias /other-system /httpdocs/other-system See Alias. In .htaccess, instead you can use RewriteEngine on RewriteRule ^/other-system/(.*) /httpdocs/other-system/$1 [QSA]


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

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

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

The cleaner, way would be: if ( $scheme = "https" ) { return 301 http://example.com$request_uri or somewhere between that and Nathans answer, where your default ssl server block contains simply the return 301 (whichever ssl block it is, you'll have to take a close look at yours to see how its implemented and adapt) No point in doing regex for a simple ...


2

Try installing the hotfix from http://support.microsoft.com/kb/2749660 The hotfix will update rewrite.dll to version 7.1.1678.0 Another potential cause of access violations is faulty RAM, so it may be worthwhile running a memory diagnostic tool such as MemTest.


2

The tilde instructs nginx to perform a case-sensitive regular expression match, instead of a straight string comparison. More details in the docs.


2

You can check if mod_alias is enabled by using the following command: ~$ apache2ctl -M | grep alias alias_module (shared) Syntax OK You can also check manually the file which is loading the module: ~$ cat /etc/apache2/mods-enabled/alias.load LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so


2

Above answer doesn't work any more for IE11 because string "MSIE" isn't available any more in user agent string. Sample IE11: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko Sample IE9: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)


2

posted answers from OP comment The problem was caused by HSTS header. In main domain, there is entry includeSubDomains in HSTS header . If a browser visits main domain and receive that HSTS header, the browser will force to connect via HTTPS in main domain and subdomain too. So, its pretty clear that nginx doesn't cause the redirection. If you don't want ...


2

To have bar.html as index file use location /foo { index bar.html; } If you wish any request to /foo/anything end up in /foo/bar.html use this: location = /foo { try_files /foo/bar.html =404; } location /foo/ { try_files /foo/bar.html =404; } In your locationyou have wrong root directive. It your confin nginx end up looking for file ...


2

I also posted this question to StatusWolf's GitHub site, and the developer just got back to me. The cause of the problem is that I'm using a very old browser: StatusWolf is using 'window.location.origin' in the widget javascript to build the URL for loading files and making API calls. You're using an older version of Firefox (14.0.1, current is 26), ...


2

When adding a rewrite rules to a site it should save it in the site's web.config. One reason I can think of why you don't see it there, is that you added the rule on the server level rather than the site level. When done on the server level it is saved in the ApplicationHost.config file. %systemroot%\System32\inetsrv\config\applicationHost.config You ...


2

First of all, the server_name directive is invalid in your main server block. server_name contains only the domain name, not any other parts of the URL. To answer your actual question, add the following configuration: location = / { rewrite ^ http://domain.com permanent; } This makes all URIs that match the exact / location redirect to ...


2

There are several problems in your configuration. First, you are using root directive inside locations. This is most likely the reason for 404 errors. You should change the first location block to start like this: location /postfixadmin { alias /var/www/html/postfixadmin/; Then, you should remove the root directive from the first inner location ...


2

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;


2

server { ... rewrite ^/widget$ /widget/index.php last; rewrite ^/widget/$ /widget/index.php last; rewrite ^/widget\?act=list$ /widget/index.php?act=list last; rewrite ^/widget/\?act=list$ /widget/index.php?act=list last; rewrite ^/widget/list$ ...



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