Nginx redirect hopping
I'm having an issue with some sites where the redirect chain looks like this:
http://example.com > https://example.com > https://www.example.com
The sites exist at the final URL, but has backlinks from other sites to the first URL. As such I would like to eliminate the middle URL to gain a little bit more of that sweet sweet Google juice.
Currently, our nginx conf document is set up thusly:
server {
listen 1.1.1.1:443 ssl http2;
listen 1.1.1.1:80;
server_name www.example.com *.www.example.com;
set $WP_ROOT /var/www/vhosts/www.example.com/htdocs;
root $WP_ROOT;
if ($scheme = http) {
return 301 https://www.example.com$request_uri;
}
access_log /var/log/nginx/www.example.com-access.log main buffer=32k;# flush=300;
error_log /var/log/nginx/www.example.com-error.log;
ssl_certificate /etc/ssl/certs/domain.crt;
ssl_certificate_key /etc/ssl/certs/domain.rsa;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon image/webp application/json application/vnd.ms-access application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
location / {
limit_req zone=limit burst=20;
try_files $uri $uri/ /index.php?$args;
include /etc/nginx/conf.d/www.example.com.redirects;
}
}
There's more but the rest is irrelevant.
My basic question is, how can I reconfigure the config to read the redirects document and redirect directly to those URLs BEFORE the force HTTPS statement, so that I only get one redirect instead of two?
nginx seo
add a comment |
I'm having an issue with some sites where the redirect chain looks like this:
http://example.com > https://example.com > https://www.example.com
The sites exist at the final URL, but has backlinks from other sites to the first URL. As such I would like to eliminate the middle URL to gain a little bit more of that sweet sweet Google juice.
Currently, our nginx conf document is set up thusly:
server {
listen 1.1.1.1:443 ssl http2;
listen 1.1.1.1:80;
server_name www.example.com *.www.example.com;
set $WP_ROOT /var/www/vhosts/www.example.com/htdocs;
root $WP_ROOT;
if ($scheme = http) {
return 301 https://www.example.com$request_uri;
}
access_log /var/log/nginx/www.example.com-access.log main buffer=32k;# flush=300;
error_log /var/log/nginx/www.example.com-error.log;
ssl_certificate /etc/ssl/certs/domain.crt;
ssl_certificate_key /etc/ssl/certs/domain.rsa;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon image/webp application/json application/vnd.ms-access application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
location / {
limit_req zone=limit burst=20;
try_files $uri $uri/ /index.php?$args;
include /etc/nginx/conf.d/www.example.com.redirects;
}
}
There's more but the rest is irrelevant.
My basic question is, how can I reconfigure the config to read the redirects document and redirect directly to those URLs BEFORE the force HTTPS statement, so that I only get one redirect instead of two?
nginx seo
Rather than usingif
magic, setup one trueserver
block and a catch-all for every other scheme/name combination. See this answer.
– Richard Smith
22 hours ago
Is it only on the $host "example.com" ? (not in www). Change the server{} bracket of example.com to redirect to example.com, if anyway everything will end on example.com, why do steps in the middle? Hope I helped.
– flaixman
22 hours ago
@flaixman The domain exists at www. and must only exist there.
– ThallerThanYall
22 hours ago
@RichardSmith Thanks for pointing me at that answer, I'll take a look and see if I can get this to work
– ThallerThanYall
22 hours ago
@ThallerThanYall then an specific configuration for non-www example.com redirecting everything to example.com$request_uri like Richard says, should work.
– flaixman
22 hours ago
add a comment |
I'm having an issue with some sites where the redirect chain looks like this:
http://example.com > https://example.com > https://www.example.com
The sites exist at the final URL, but has backlinks from other sites to the first URL. As such I would like to eliminate the middle URL to gain a little bit more of that sweet sweet Google juice.
Currently, our nginx conf document is set up thusly:
server {
listen 1.1.1.1:443 ssl http2;
listen 1.1.1.1:80;
server_name www.example.com *.www.example.com;
set $WP_ROOT /var/www/vhosts/www.example.com/htdocs;
root $WP_ROOT;
if ($scheme = http) {
return 301 https://www.example.com$request_uri;
}
access_log /var/log/nginx/www.example.com-access.log main buffer=32k;# flush=300;
error_log /var/log/nginx/www.example.com-error.log;
ssl_certificate /etc/ssl/certs/domain.crt;
ssl_certificate_key /etc/ssl/certs/domain.rsa;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon image/webp application/json application/vnd.ms-access application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
location / {
limit_req zone=limit burst=20;
try_files $uri $uri/ /index.php?$args;
include /etc/nginx/conf.d/www.example.com.redirects;
}
}
There's more but the rest is irrelevant.
My basic question is, how can I reconfigure the config to read the redirects document and redirect directly to those URLs BEFORE the force HTTPS statement, so that I only get one redirect instead of two?
nginx seo
I'm having an issue with some sites where the redirect chain looks like this:
http://example.com > https://example.com > https://www.example.com
The sites exist at the final URL, but has backlinks from other sites to the first URL. As such I would like to eliminate the middle URL to gain a little bit more of that sweet sweet Google juice.
Currently, our nginx conf document is set up thusly:
server {
listen 1.1.1.1:443 ssl http2;
listen 1.1.1.1:80;
server_name www.example.com *.www.example.com;
set $WP_ROOT /var/www/vhosts/www.example.com/htdocs;
root $WP_ROOT;
if ($scheme = http) {
return 301 https://www.example.com$request_uri;
}
access_log /var/log/nginx/www.example.com-access.log main buffer=32k;# flush=300;
error_log /var/log/nginx/www.example.com-error.log;
ssl_certificate /etc/ssl/certs/domain.crt;
ssl_certificate_key /etc/ssl/certs/domain.rsa;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon image/webp application/json application/vnd.ms-access application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
location / {
limit_req zone=limit burst=20;
try_files $uri $uri/ /index.php?$args;
include /etc/nginx/conf.d/www.example.com.redirects;
}
}
There's more but the rest is irrelevant.
My basic question is, how can I reconfigure the config to read the redirects document and redirect directly to those URLs BEFORE the force HTTPS statement, so that I only get one redirect instead of two?
nginx seo
nginx seo
asked 23 hours ago
ThallerThanYall
12712
12712
Rather than usingif
magic, setup one trueserver
block and a catch-all for every other scheme/name combination. See this answer.
– Richard Smith
22 hours ago
Is it only on the $host "example.com" ? (not in www). Change the server{} bracket of example.com to redirect to example.com, if anyway everything will end on example.com, why do steps in the middle? Hope I helped.
– flaixman
22 hours ago
@flaixman The domain exists at www. and must only exist there.
– ThallerThanYall
22 hours ago
@RichardSmith Thanks for pointing me at that answer, I'll take a look and see if I can get this to work
– ThallerThanYall
22 hours ago
@ThallerThanYall then an specific configuration for non-www example.com redirecting everything to example.com$request_uri like Richard says, should work.
– flaixman
22 hours ago
add a comment |
Rather than usingif
magic, setup one trueserver
block and a catch-all for every other scheme/name combination. See this answer.
– Richard Smith
22 hours ago
Is it only on the $host "example.com" ? (not in www). Change the server{} bracket of example.com to redirect to example.com, if anyway everything will end on example.com, why do steps in the middle? Hope I helped.
– flaixman
22 hours ago
@flaixman The domain exists at www. and must only exist there.
– ThallerThanYall
22 hours ago
@RichardSmith Thanks for pointing me at that answer, I'll take a look and see if I can get this to work
– ThallerThanYall
22 hours ago
@ThallerThanYall then an specific configuration for non-www example.com redirecting everything to example.com$request_uri like Richard says, should work.
– flaixman
22 hours ago
Rather than using
if
magic, setup one true server
block and a catch-all for every other scheme/name combination. See this answer.– Richard Smith
22 hours ago
Rather than using
if
magic, setup one true server
block and a catch-all for every other scheme/name combination. See this answer.– Richard Smith
22 hours ago
Is it only on the $host "example.com" ? (not in www). Change the server{} bracket of example.com to redirect to example.com, if anyway everything will end on example.com, why do steps in the middle? Hope I helped.
– flaixman
22 hours ago
Is it only on the $host "example.com" ? (not in www). Change the server{} bracket of example.com to redirect to example.com, if anyway everything will end on example.com, why do steps in the middle? Hope I helped.
– flaixman
22 hours ago
@flaixman The domain exists at www. and must only exist there.
– ThallerThanYall
22 hours ago
@flaixman The domain exists at www. and must only exist there.
– ThallerThanYall
22 hours ago
@RichardSmith Thanks for pointing me at that answer, I'll take a look and see if I can get this to work
– ThallerThanYall
22 hours ago
@RichardSmith Thanks for pointing me at that answer, I'll take a look and see if I can get this to work
– ThallerThanYall
22 hours ago
@ThallerThanYall then an specific configuration for non-www example.com redirecting everything to example.com$request_uri like Richard says, should work.
– flaixman
22 hours ago
@ThallerThanYall then an specific configuration for non-www example.com redirecting everything to example.com$request_uri like Richard says, should work.
– flaixman
22 hours ago
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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%2fstackoverflow.com%2fquestions%2f53943200%2fnginx-redirect-hopping%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2fstackoverflow.com%2fquestions%2f53943200%2fnginx-redirect-hopping%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
Rather than using
if
magic, setup one trueserver
block and a catch-all for every other scheme/name combination. See this answer.– Richard Smith
22 hours ago
Is it only on the $host "example.com" ? (not in www). Change the server{} bracket of example.com to redirect to example.com, if anyway everything will end on example.com, why do steps in the middle? Hope I helped.
– flaixman
22 hours ago
@flaixman The domain exists at www. and must only exist there.
– ThallerThanYall
22 hours ago
@RichardSmith Thanks for pointing me at that answer, I'll take a look and see if I can get this to work
– ThallerThanYall
22 hours ago
@ThallerThanYall then an specific configuration for non-www example.com redirecting everything to example.com$request_uri like Richard says, should work.
– flaixman
22 hours ago