Nginx map directive not matching rulesHow to make nginx reverse proxy let 503 error pages pass through to...
Error in master's thesis, I do not know what to do
CLI: Get information Ubuntu releases
Do native speakers use "ultima" and "proxima" frequently in spoken English?
PTIJ: At the Passover Seder, is one allowed to speak more than once during Maggid?
Why is "la Gestapo" feminine?
Do people actually use the word "kaputt" in conversation?
How to test the sharpness of a knife?
Do I need an EFI partition for each 18.04 ubuntu I have on my HD?
Can "few" be used as a subject? If so, what is the rule?
Emojional cryptic crossword
Does fire aspect on a sword, destroy mob drops?
Air travel with refrigerated insulin
Is there any common country to visit for uk and schengen visa?
Symbolism of 18 Journeyers
PTIJ: Which Dr. Seuss books should one obtain?
How do researchers send unsolicited emails asking for feedback on their works?
Is this Pascal's Matrix?
How do you justify more code being written by following clean code practices?
DisplayForm problem with pi in FractionBox
Should a narrator ever describe things based on a characters view instead of fact?
Why is participating in the European Parliamentary elections used as a threat?
Why does Surtur say that Thor is Asgard's doom?
Determine voltage drop over 10G resistors with cheap multimeter
10 year ban after applying for a UK student visa
Nginx map directive not matching rules
How to make nginx reverse proxy let 503 error pages pass through to client?Nginx Redirect Url containing “PHP”nginx redirect issue with upstream configurationProperly setting up a “default” nginx server for httpsNginx robots.txt configurationCodeIgniter nginx rewrite rules for i8ln URL'sUniversal HTTPS to HTTP reverse proxy using nginxConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errorsNGINX virtual host config for Magento2 in a subfolderNginx reverse proxy to many local servers + webserver duty
I have this nginx config file:
map $request_uri $new_uri {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri;
add_header X-return_code $ret_code;
if ($new_uri = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code = 301) {
return 301 $new_uri;
}
if ($ret_code = 302) {
return 302 $new_uri;
}
}
}
The map directive is not working at all, just defaulting to whatever its defined for default.
For example:
$ curl -I testdomain.com/lol
HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.0 (Ubuntu)
Date: Sun, 22 Jan 2017 20:04:06 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://ashfame.com/lol
X-request_uri: /lol
X-new_uri: DEFAULT
X-return_code: 301
/lol
should have set $new_uri
as http://lol.com
and $ret_code
as 302
, but if you look at the X-
headers, its just taking the default values specified in the mapping.
A week back I got this same nginx config working, and there hasn't been any change since then. I do have ubuntu's auto security upgrades on, but don't think nginx was even updated. Running v1.10.0
. Can't really point out why this stopped working.
Edit: Just tested this same config on a different VPS, same nginx version and it works over there correctly. How do I even fix this now?
nginx redirection
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have this nginx config file:
map $request_uri $new_uri {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri;
add_header X-return_code $ret_code;
if ($new_uri = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code = 301) {
return 301 $new_uri;
}
if ($ret_code = 302) {
return 302 $new_uri;
}
}
}
The map directive is not working at all, just defaulting to whatever its defined for default.
For example:
$ curl -I testdomain.com/lol
HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.0 (Ubuntu)
Date: Sun, 22 Jan 2017 20:04:06 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://ashfame.com/lol
X-request_uri: /lol
X-new_uri: DEFAULT
X-return_code: 301
/lol
should have set $new_uri
as http://lol.com
and $ret_code
as 302
, but if you look at the X-
headers, its just taking the default values specified in the mapping.
A week back I got this same nginx config working, and there hasn't been any change since then. I do have ubuntu's auto security upgrades on, but don't think nginx was even updated. Running v1.10.0
. Can't really point out why this stopped working.
Edit: Just tested this same config on a different VPS, same nginx version and it works over there correctly. How do I even fix this now?
nginx redirection
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have this nginx config file:
map $request_uri $new_uri {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri;
add_header X-return_code $ret_code;
if ($new_uri = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code = 301) {
return 301 $new_uri;
}
if ($ret_code = 302) {
return 302 $new_uri;
}
}
}
The map directive is not working at all, just defaulting to whatever its defined for default.
For example:
$ curl -I testdomain.com/lol
HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.0 (Ubuntu)
Date: Sun, 22 Jan 2017 20:04:06 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://ashfame.com/lol
X-request_uri: /lol
X-new_uri: DEFAULT
X-return_code: 301
/lol
should have set $new_uri
as http://lol.com
and $ret_code
as 302
, but if you look at the X-
headers, its just taking the default values specified in the mapping.
A week back I got this same nginx config working, and there hasn't been any change since then. I do have ubuntu's auto security upgrades on, but don't think nginx was even updated. Running v1.10.0
. Can't really point out why this stopped working.
Edit: Just tested this same config on a different VPS, same nginx version and it works over there correctly. How do I even fix this now?
nginx redirection
I have this nginx config file:
map $request_uri $new_uri {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri;
add_header X-return_code $ret_code;
if ($new_uri = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code = 301) {
return 301 $new_uri;
}
if ($ret_code = 302) {
return 302 $new_uri;
}
}
}
The map directive is not working at all, just defaulting to whatever its defined for default.
For example:
$ curl -I testdomain.com/lol
HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.0 (Ubuntu)
Date: Sun, 22 Jan 2017 20:04:06 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://ashfame.com/lol
X-request_uri: /lol
X-new_uri: DEFAULT
X-return_code: 301
/lol
should have set $new_uri
as http://lol.com
and $ret_code
as 302
, but if you look at the X-
headers, its just taking the default values specified in the mapping.
A week back I got this same nginx config working, and there hasn't been any change since then. I do have ubuntu's auto security upgrades on, but don't think nginx was even updated. Running v1.10.0
. Can't really point out why this stopped working.
Edit: Just tested this same config on a different VPS, same nginx version and it works over there correctly. How do I even fix this now?
nginx redirection
nginx redirection
edited Jan 22 '17 at 20:33
Ashfame
asked Jan 22 '17 at 20:20
AshfameAshfame
15710
15710
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I figured out the issue. I had multiples of such config files for each domain and since map is defined in http context the last one was overwriting the value of variables. I fixed it by suffixing the variable name in each config file, so that variables are unique:
map $request_uri $new_uri_5 {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code_5 {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com testdomain.com www.testdomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri_5;
add_header X-return_code $ret_code_5;
if ($new_uri_5 = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code_5 = 301) {
return 301 $new_uri_5;
}
if ($ret_code_5 = 302) {
return 302 $new_uri_5;
}
}
}
5 is the ID of this particular domain in my system.
Wow, many answers on serverfault but no one pointed that the variables need to be unique on each domain configuration file. I've been wondering why mapping works one one configuration file but not working on another website. Now it all make sense.
– Someone Special
Oct 1 '18 at 10:24
add a comment |
I've been experiencing the same issue on Nginx 1.12.2 -- map directive would not match any of the patterns, even the simplest and most trivial ones like /
, and always used the default value.
The issue tuned out to be caused by the use of the $uri
variable in the mapping. Some Nginx configuration was implicitly modifying the $uri
from its original value by prepending /index.php
prefix which caused the pattern mismatch. Such behavior of $uri
is by design and the exact distinction between $request_uri
and $uri
variables.
The fix was to replace the URI variable in the Nginx config:
map $uri $result_var {
# ...
}
with the following:
map $request_uri $result_var {
# ...
}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f827866%2fnginx-map-directive-not-matching-rules%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I figured out the issue. I had multiples of such config files for each domain and since map is defined in http context the last one was overwriting the value of variables. I fixed it by suffixing the variable name in each config file, so that variables are unique:
map $request_uri $new_uri_5 {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code_5 {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com testdomain.com www.testdomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri_5;
add_header X-return_code $ret_code_5;
if ($new_uri_5 = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code_5 = 301) {
return 301 $new_uri_5;
}
if ($ret_code_5 = 302) {
return 302 $new_uri_5;
}
}
}
5 is the ID of this particular domain in my system.
Wow, many answers on serverfault but no one pointed that the variables need to be unique on each domain configuration file. I've been wondering why mapping works one one configuration file but not working on another website. Now it all make sense.
– Someone Special
Oct 1 '18 at 10:24
add a comment |
I figured out the issue. I had multiples of such config files for each domain and since map is defined in http context the last one was overwriting the value of variables. I fixed it by suffixing the variable name in each config file, so that variables are unique:
map $request_uri $new_uri_5 {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code_5 {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com testdomain.com www.testdomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri_5;
add_header X-return_code $ret_code_5;
if ($new_uri_5 = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code_5 = 301) {
return 301 $new_uri_5;
}
if ($ret_code_5 = 302) {
return 302 $new_uri_5;
}
}
}
5 is the ID of this particular domain in my system.
Wow, many answers on serverfault but no one pointed that the variables need to be unique on each domain configuration file. I've been wondering why mapping works one one configuration file but not working on another website. Now it all make sense.
– Someone Special
Oct 1 '18 at 10:24
add a comment |
I figured out the issue. I had multiples of such config files for each domain and since map is defined in http context the last one was overwriting the value of variables. I fixed it by suffixing the variable name in each config file, so that variables are unique:
map $request_uri $new_uri_5 {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code_5 {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com testdomain.com www.testdomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri_5;
add_header X-return_code $ret_code_5;
if ($new_uri_5 = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code_5 = 301) {
return 301 $new_uri_5;
}
if ($ret_code_5 = 302) {
return 302 $new_uri_5;
}
}
}
5 is the ID of this particular domain in my system.
I figured out the issue. I had multiples of such config files for each domain and since map is defined in http context the last one was overwriting the value of variables. I fixed it by suffixing the variable name in each config file, so that variables are unique:
map $request_uri $new_uri_5 {
default DEFAULT;
/shell http://shell.com;
/lol http://lol.com;
}
map $request_uri $ret_code_5 {
default 301;
/shell 301;
/lol 302;
}
server {
listen 80;
server_name TestDomain.com www.TestDomain.com testdomain.com www.testdomain.com;
location / {
add_header X-request_uri $request_uri;
add_header X-new_uri $new_uri_5;
add_header X-return_code $ret_code_5;
if ($new_uri_5 = "DEFAULT") {
return 301 https://ashfame.com$request_uri;
}
if ($ret_code_5 = 301) {
return 301 $new_uri_5;
}
if ($ret_code_5 = 302) {
return 302 $new_uri_5;
}
}
}
5 is the ID of this particular domain in my system.
answered Jan 23 '17 at 10:31
AshfameAshfame
15710
15710
Wow, many answers on serverfault but no one pointed that the variables need to be unique on each domain configuration file. I've been wondering why mapping works one one configuration file but not working on another website. Now it all make sense.
– Someone Special
Oct 1 '18 at 10:24
add a comment |
Wow, many answers on serverfault but no one pointed that the variables need to be unique on each domain configuration file. I've been wondering why mapping works one one configuration file but not working on another website. Now it all make sense.
– Someone Special
Oct 1 '18 at 10:24
Wow, many answers on serverfault but no one pointed that the variables need to be unique on each domain configuration file. I've been wondering why mapping works one one configuration file but not working on another website. Now it all make sense.
– Someone Special
Oct 1 '18 at 10:24
Wow, many answers on serverfault but no one pointed that the variables need to be unique on each domain configuration file. I've been wondering why mapping works one one configuration file but not working on another website. Now it all make sense.
– Someone Special
Oct 1 '18 at 10:24
add a comment |
I've been experiencing the same issue on Nginx 1.12.2 -- map directive would not match any of the patterns, even the simplest and most trivial ones like /
, and always used the default value.
The issue tuned out to be caused by the use of the $uri
variable in the mapping. Some Nginx configuration was implicitly modifying the $uri
from its original value by prepending /index.php
prefix which caused the pattern mismatch. Such behavior of $uri
is by design and the exact distinction between $request_uri
and $uri
variables.
The fix was to replace the URI variable in the Nginx config:
map $uri $result_var {
# ...
}
with the following:
map $request_uri $result_var {
# ...
}
add a comment |
I've been experiencing the same issue on Nginx 1.12.2 -- map directive would not match any of the patterns, even the simplest and most trivial ones like /
, and always used the default value.
The issue tuned out to be caused by the use of the $uri
variable in the mapping. Some Nginx configuration was implicitly modifying the $uri
from its original value by prepending /index.php
prefix which caused the pattern mismatch. Such behavior of $uri
is by design and the exact distinction between $request_uri
and $uri
variables.
The fix was to replace the URI variable in the Nginx config:
map $uri $result_var {
# ...
}
with the following:
map $request_uri $result_var {
# ...
}
add a comment |
I've been experiencing the same issue on Nginx 1.12.2 -- map directive would not match any of the patterns, even the simplest and most trivial ones like /
, and always used the default value.
The issue tuned out to be caused by the use of the $uri
variable in the mapping. Some Nginx configuration was implicitly modifying the $uri
from its original value by prepending /index.php
prefix which caused the pattern mismatch. Such behavior of $uri
is by design and the exact distinction between $request_uri
and $uri
variables.
The fix was to replace the URI variable in the Nginx config:
map $uri $result_var {
# ...
}
with the following:
map $request_uri $result_var {
# ...
}
I've been experiencing the same issue on Nginx 1.12.2 -- map directive would not match any of the patterns, even the simplest and most trivial ones like /
, and always used the default value.
The issue tuned out to be caused by the use of the $uri
variable in the mapping. Some Nginx configuration was implicitly modifying the $uri
from its original value by prepending /index.php
prefix which caused the pattern mismatch. Such behavior of $uri
is by design and the exact distinction between $request_uri
and $uri
variables.
The fix was to replace the URI variable in the Nginx config:
map $uri $result_var {
# ...
}
with the following:
map $request_uri $result_var {
# ...
}
edited Feb 17 at 0:00
answered Feb 16 at 23:55
Sergii ShymkoSergii Shymko
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f827866%2fnginx-map-directive-not-matching-rules%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown