Nginx: map subdomain to a subdirectory on proxied serverHelp needed setting up nginx to serve static...
Have I saved too much for retirement so far?
My boss asked me to take a one-day class, then signs it up as a day off
Greatest common substring
Can the harmonic series explain the origin of the major scale?
Simple recursive Sudoku solver
Can a Bard use an arcane focus?
What is the opposite of 'gravitas'?
Lightning Web Component - do I need to track changes for every single input field in a form
Can I Retrieve Email Addresses from BCC?
What does the "3am" section means in manpages?
Books on the History of math research at European universities
Simple image editor tool to draw a simple box/rectangle in an existing image
For airliners, what prevents wing strikes on landing in bad weather?
Identify a stage play about a VR experience in which participants are encouraged to simulate performing horrific activities
Giant Toughroad SLR 2 for 200 miles in two days, will it make it?
Could solar power be utilized and substitute coal in the 19th century?
Science Fiction story where a man invents a machine that can help him watch history unfold
Is there enough fresh water in the world to eradicate the drinking water crisis?
Can the electrostatic force be infinite in magnitude?
Is it okay / does it make sense for another player to join a running game of Munchkin?
Pronouncing Homer as in modern Greek
Does "Dominei" mean something?
Can a malicious addon access internet history and such in chrome/firefox?
Meta programming: Declare a new struct on the fly
Nginx: map subdomain to a subdirectory on proxied server
Help needed setting up nginx to serve static filesBlank Page: wordpress on nginx+php-fpmnginx redirect issue with upstream configurationNginx proxy pass works for https but not httpnginx proxy redirecting request to different proxyNginx subversion commit failurenginx reverse proxy hide login query also on 301 redirect or full qualified urlCodeIgniter nginx rewrite rules for i8ln URL'sMap subdomain to subdirectory and custom header to basic authenticationNginx reverse proxy to many local servers + webserver duty
I have domain example.com
and subdomain blog.example.com
. I have an Unicorn application running at localhost:5000
, and use Nginx as a reverse proxy.
I had no issues when running just the example.com
. However I want to add subdomain support and have some issues.
I have some content at example.com/blog
. I want blog.example.com
to point to it, without user knowledge that a rewrite is used. I want to map all URLS, so that:
blog.example.com
->localhost:5000/blog
blog.example.com/index.php
->localhost:5000/blog/index.php
blog.example.com/foo/bar
->localhost:5000/blog/foo/bar
My best attempt so far it this:
server
{
listen 80;
server_name blog.example.com;
location / {
proxy_pass http://localhost:5000/blog/$uri;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
client_max_body_size 4G;
keepalive_timeout 10;
}
This correctly rewrites blog.example.com
, but fails with blog.example.com/index.php
:
$ curl -v 'http://blog.example.com'
> GET /index.php HTTP/1.1
> Host: blog.example.com
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Sun, 26 Mar 2017 12:29:00 GMT
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 337
< Connection: keep-alive
< Location: http://blog.example.com/blog/index.php
nginx proxy rewrite subdomain
add a comment |
I have domain example.com
and subdomain blog.example.com
. I have an Unicorn application running at localhost:5000
, and use Nginx as a reverse proxy.
I had no issues when running just the example.com
. However I want to add subdomain support and have some issues.
I have some content at example.com/blog
. I want blog.example.com
to point to it, without user knowledge that a rewrite is used. I want to map all URLS, so that:
blog.example.com
->localhost:5000/blog
blog.example.com/index.php
->localhost:5000/blog/index.php
blog.example.com/foo/bar
->localhost:5000/blog/foo/bar
My best attempt so far it this:
server
{
listen 80;
server_name blog.example.com;
location / {
proxy_pass http://localhost:5000/blog/$uri;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
client_max_body_size 4G;
keepalive_timeout 10;
}
This correctly rewrites blog.example.com
, but fails with blog.example.com/index.php
:
$ curl -v 'http://blog.example.com'
> GET /index.php HTTP/1.1
> Host: blog.example.com
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Sun, 26 Mar 2017 12:29:00 GMT
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 337
< Connection: keep-alive
< Location: http://blog.example.com/blog/index.php
nginx proxy rewrite subdomain
I think this is something in your blog software configuration that makes it return the redirect.
– Tero Kilkanen
Mar 26 '17 at 14:28
No, this is on nginx level. I set up a script at/blog
that does nothing except printing env info (likephp_info()
) and I'm still getting the 301 from nginx. Also, when it starts to redirect to/blog
, it creates a loop (/blog/blog/blog/blog/.../blog/index.php
).
– Michael
Mar 26 '17 at 14:33
add a comment |
I have domain example.com
and subdomain blog.example.com
. I have an Unicorn application running at localhost:5000
, and use Nginx as a reverse proxy.
I had no issues when running just the example.com
. However I want to add subdomain support and have some issues.
I have some content at example.com/blog
. I want blog.example.com
to point to it, without user knowledge that a rewrite is used. I want to map all URLS, so that:
blog.example.com
->localhost:5000/blog
blog.example.com/index.php
->localhost:5000/blog/index.php
blog.example.com/foo/bar
->localhost:5000/blog/foo/bar
My best attempt so far it this:
server
{
listen 80;
server_name blog.example.com;
location / {
proxy_pass http://localhost:5000/blog/$uri;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
client_max_body_size 4G;
keepalive_timeout 10;
}
This correctly rewrites blog.example.com
, but fails with blog.example.com/index.php
:
$ curl -v 'http://blog.example.com'
> GET /index.php HTTP/1.1
> Host: blog.example.com
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Sun, 26 Mar 2017 12:29:00 GMT
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 337
< Connection: keep-alive
< Location: http://blog.example.com/blog/index.php
nginx proxy rewrite subdomain
I have domain example.com
and subdomain blog.example.com
. I have an Unicorn application running at localhost:5000
, and use Nginx as a reverse proxy.
I had no issues when running just the example.com
. However I want to add subdomain support and have some issues.
I have some content at example.com/blog
. I want blog.example.com
to point to it, without user knowledge that a rewrite is used. I want to map all URLS, so that:
blog.example.com
->localhost:5000/blog
blog.example.com/index.php
->localhost:5000/blog/index.php
blog.example.com/foo/bar
->localhost:5000/blog/foo/bar
My best attempt so far it this:
server
{
listen 80;
server_name blog.example.com;
location / {
proxy_pass http://localhost:5000/blog/$uri;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
client_max_body_size 4G;
keepalive_timeout 10;
}
This correctly rewrites blog.example.com
, but fails with blog.example.com/index.php
:
$ curl -v 'http://blog.example.com'
> GET /index.php HTTP/1.1
> Host: blog.example.com
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Sun, 26 Mar 2017 12:29:00 GMT
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 337
< Connection: keep-alive
< Location: http://blog.example.com/blog/index.php
nginx proxy rewrite subdomain
nginx proxy rewrite subdomain
asked Mar 26 '17 at 12:39
MichaelMichael
113
113
I think this is something in your blog software configuration that makes it return the redirect.
– Tero Kilkanen
Mar 26 '17 at 14:28
No, this is on nginx level. I set up a script at/blog
that does nothing except printing env info (likephp_info()
) and I'm still getting the 301 from nginx. Also, when it starts to redirect to/blog
, it creates a loop (/blog/blog/blog/blog/.../blog/index.php
).
– Michael
Mar 26 '17 at 14:33
add a comment |
I think this is something in your blog software configuration that makes it return the redirect.
– Tero Kilkanen
Mar 26 '17 at 14:28
No, this is on nginx level. I set up a script at/blog
that does nothing except printing env info (likephp_info()
) and I'm still getting the 301 from nginx. Also, when it starts to redirect to/blog
, it creates a loop (/blog/blog/blog/blog/.../blog/index.php
).
– Michael
Mar 26 '17 at 14:33
I think this is something in your blog software configuration that makes it return the redirect.
– Tero Kilkanen
Mar 26 '17 at 14:28
I think this is something in your blog software configuration that makes it return the redirect.
– Tero Kilkanen
Mar 26 '17 at 14:28
No, this is on nginx level. I set up a script at
/blog
that does nothing except printing env info (like php_info()
) and I'm still getting the 301 from nginx. Also, when it starts to redirect to /blog
, it creates a loop (/blog/blog/blog/blog/.../blog/index.php
).– Michael
Mar 26 '17 at 14:33
No, this is on nginx level. I set up a script at
/blog
that does nothing except printing env info (like php_info()
) and I'm still getting the 301 from nginx. Also, when it starts to redirect to /blog
, it creates a loop (/blog/blog/blog/blog/.../blog/index.php
).– Michael
Mar 26 '17 at 14:33
add a comment |
2 Answers
2
active
oldest
votes
I found that my mistake was at this line:
proxy_pass http://localhost:5000/blog/$uri;
When changed to
proxy_pass http://localhost:5000/blog$uri;
the proxy works as expected.
[edit]
Even better version, to also pass query string:
proxy_pass http://localhost:5000/blog$uri$is_args$args;
add a comment |
Do you have a problem with styles and javascripts?
The assets in my case throw an error (404)
New contributor
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%2f840654%2fnginx-map-subdomain-to-a-subdirectory-on-proxied-server%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 found that my mistake was at this line:
proxy_pass http://localhost:5000/blog/$uri;
When changed to
proxy_pass http://localhost:5000/blog$uri;
the proxy works as expected.
[edit]
Even better version, to also pass query string:
proxy_pass http://localhost:5000/blog$uri$is_args$args;
add a comment |
I found that my mistake was at this line:
proxy_pass http://localhost:5000/blog/$uri;
When changed to
proxy_pass http://localhost:5000/blog$uri;
the proxy works as expected.
[edit]
Even better version, to also pass query string:
proxy_pass http://localhost:5000/blog$uri$is_args$args;
add a comment |
I found that my mistake was at this line:
proxy_pass http://localhost:5000/blog/$uri;
When changed to
proxy_pass http://localhost:5000/blog$uri;
the proxy works as expected.
[edit]
Even better version, to also pass query string:
proxy_pass http://localhost:5000/blog$uri$is_args$args;
I found that my mistake was at this line:
proxy_pass http://localhost:5000/blog/$uri;
When changed to
proxy_pass http://localhost:5000/blog$uri;
the proxy works as expected.
[edit]
Even better version, to also pass query string:
proxy_pass http://localhost:5000/blog$uri$is_args$args;
edited Mar 26 '17 at 15:00
answered Mar 26 '17 at 14:42
MichaelMichael
113
113
add a comment |
add a comment |
Do you have a problem with styles and javascripts?
The assets in my case throw an error (404)
New contributor
add a comment |
Do you have a problem with styles and javascripts?
The assets in my case throw an error (404)
New contributor
add a comment |
Do you have a problem with styles and javascripts?
The assets in my case throw an error (404)
New contributor
Do you have a problem with styles and javascripts?
The assets in my case throw an error (404)
New contributor
New contributor
answered 1 min ago
drmartindrmartin
1011
1011
New contributor
New contributor
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%2f840654%2fnginx-map-subdomain-to-a-subdirectory-on-proxied-server%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
I think this is something in your blog software configuration that makes it return the redirect.
– Tero Kilkanen
Mar 26 '17 at 14:28
No, this is on nginx level. I set up a script at
/blog
that does nothing except printing env info (likephp_info()
) and I'm still getting the 301 from nginx. Also, when it starts to redirect to/blog
, it creates a loop (/blog/blog/blog/blog/.../blog/index.php
).– Michael
Mar 26 '17 at 14:33