nginx does not respect server_name Announcing the arrival of Valued Associate #679: Cesar...
How widely used is the term Treppenwitz? Is it something that most Germans know?
Error "illegal generic type for instanceof" when using local classes
How does the particle を relate to the verb 行く in the structure「A を + B に行く」?
Why are there no cargo aircraft with "flying wing" design?
How to tell that you are a giant?
List *all* the tuples!
How to align text above triangle figure
How to run gsettings for another user Ubuntu 18.04.2 LTS
Storing hydrofluoric acid before the invention of plastics
Sci-Fi book where patients in a coma ward all live in a subconscious world linked together
Can an alien society believe that their star system is the universe?
What causes the vertical darker bands in my photo?
Should I use a zero-interest credit card for a large one-time purchase?
Why is my conclusion inconsistent with the van't Hoff equation?
How can I make names more distinctive without making them longer?
Why is "Consequences inflicted." not a sentence?
How to Merge Multiple Columns in to Two Columns based on Column 1 Value?
Apollo command module space walk?
Why did the rest of the Eastern Bloc not invade Yugoslavia?
3 doors, three guards, one stone
Short Story with Cinderella as a Voo-doo Witch
How do I stop a creek from eroding my steep embankment?
String `!23` is replaced with `docker` in command line
How does debian/ubuntu knows a package has a updated version
nginx does not respect server_name
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Why all subdomains are directing to same service?Nginx & UserDir & PHPnginx not accessible from public IP, but is on 127.0.0.1how to configure nginx to dispatch request to index.html and tomcat server?How to make nginx connect php-fpm with 127.0.0.1, not server's public ip?Nginx permission error on try and index (actual file works fine)dokuwiki, nginx and farmsNginx default configuration file issueHow to configure a conditional nginx proxy passNginx SSL Preread Sporadically Gets Requests Where No Server Name Is Extracted
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have two virtual hosts on my nginx server with their respective domain name. One is http only because it’s a static site (siteA), the other is https only (siteB). For siteB I have a permanent redirection from the http access to the https access.
The config for siteA
is
server {
listen 80;
listen [::]:80;
server_name siteA.example.com;
...
location / {
...
}
}
The config for siteB
is
server {
listen 80;
listen [::]:80;
server_name siteB.example.com;
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name siteB.example.com;
...
location / {
...
}
}
The problem is that when I access https://siteA.example.com
I get back https://siteB.example.com
. How may I avoid this ?
Do I have to use listen siteB.example.com:443 ssl;
instead of simply listen 443 ssl;
?
I expected that server_name
specifies the server name to match for the HOST value in the HTTP request.
nginx
add a comment |
I have two virtual hosts on my nginx server with their respective domain name. One is http only because it’s a static site (siteA), the other is https only (siteB). For siteB I have a permanent redirection from the http access to the https access.
The config for siteA
is
server {
listen 80;
listen [::]:80;
server_name siteA.example.com;
...
location / {
...
}
}
The config for siteB
is
server {
listen 80;
listen [::]:80;
server_name siteB.example.com;
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name siteB.example.com;
...
location / {
...
}
}
The problem is that when I access https://siteA.example.com
I get back https://siteB.example.com
. How may I avoid this ?
Do I have to use listen siteB.example.com:443 ssl;
instead of simply listen 443 ssl;
?
I expected that server_name
specifies the server name to match for the HOST value in the HTTP request.
nginx
add a comment |
I have two virtual hosts on my nginx server with their respective domain name. One is http only because it’s a static site (siteA), the other is https only (siteB). For siteB I have a permanent redirection from the http access to the https access.
The config for siteA
is
server {
listen 80;
listen [::]:80;
server_name siteA.example.com;
...
location / {
...
}
}
The config for siteB
is
server {
listen 80;
listen [::]:80;
server_name siteB.example.com;
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name siteB.example.com;
...
location / {
...
}
}
The problem is that when I access https://siteA.example.com
I get back https://siteB.example.com
. How may I avoid this ?
Do I have to use listen siteB.example.com:443 ssl;
instead of simply listen 443 ssl;
?
I expected that server_name
specifies the server name to match for the HOST value in the HTTP request.
nginx
I have two virtual hosts on my nginx server with their respective domain name. One is http only because it’s a static site (siteA), the other is https only (siteB). For siteB I have a permanent redirection from the http access to the https access.
The config for siteA
is
server {
listen 80;
listen [::]:80;
server_name siteA.example.com;
...
location / {
...
}
}
The config for siteB
is
server {
listen 80;
listen [::]:80;
server_name siteB.example.com;
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name siteB.example.com;
...
location / {
...
}
}
The problem is that when I access https://siteA.example.com
I get back https://siteB.example.com
. How may I avoid this ?
Do I have to use listen siteB.example.com:443 ssl;
instead of simply listen 443 ssl;
?
I expected that server_name
specifies the server name to match for the HOST value in the HTTP request.
nginx
nginx
asked 18 hours ago
chmikechmike
128117
128117
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your case is one, where a Host
header is sent, that matches none of the server_name
directives in the configuration.
Nginx (as well as Apache) will resolve this by answering the request in the context of the default_server
item which if not given is chosen from the first virtual host read.
If you have different IP addresses for the hosts, you can just chose to filter the listen
directive, but if you share IPs the canonical way is to create a dedicated default_server
item with a rewrite rule that will always return a "Host not found" page and a HTTP error, often 404.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f1425951%2fnginx-does-not-respect-server-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your case is one, where a Host
header is sent, that matches none of the server_name
directives in the configuration.
Nginx (as well as Apache) will resolve this by answering the request in the context of the default_server
item which if not given is chosen from the first virtual host read.
If you have different IP addresses for the hosts, you can just chose to filter the listen
directive, but if you share IPs the canonical way is to create a dedicated default_server
item with a rewrite rule that will always return a "Host not found" page and a HTTP error, often 404.
add a comment |
Your case is one, where a Host
header is sent, that matches none of the server_name
directives in the configuration.
Nginx (as well as Apache) will resolve this by answering the request in the context of the default_server
item which if not given is chosen from the first virtual host read.
If you have different IP addresses for the hosts, you can just chose to filter the listen
directive, but if you share IPs the canonical way is to create a dedicated default_server
item with a rewrite rule that will always return a "Host not found" page and a HTTP error, often 404.
add a comment |
Your case is one, where a Host
header is sent, that matches none of the server_name
directives in the configuration.
Nginx (as well as Apache) will resolve this by answering the request in the context of the default_server
item which if not given is chosen from the first virtual host read.
If you have different IP addresses for the hosts, you can just chose to filter the listen
directive, but if you share IPs the canonical way is to create a dedicated default_server
item with a rewrite rule that will always return a "Host not found" page and a HTTP error, often 404.
Your case is one, where a Host
header is sent, that matches none of the server_name
directives in the configuration.
Nginx (as well as Apache) will resolve this by answering the request in the context of the default_server
item which if not given is chosen from the first virtual host read.
If you have different IP addresses for the hosts, you can just chose to filter the listen
directive, but if you share IPs the canonical way is to create a dedicated default_server
item with a rewrite rule that will always return a "Host not found" page and a HTTP error, often 404.
answered 18 hours ago
Eugen RieckEugen Rieck
11.3k22429
11.3k22429
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1425951%2fnginx-does-not-respect-server-name%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