apache virtual host subdomain not working correctly
I am trying to configure a subdomain: api.example.com
(exapmle.com is replaced by my actual domain name)
I already had virtual hosts set up with 2 sites:
example.com and example.nl
they both had separate directories and where working correctly as separate sites.
Now I want to add api.example.com also with its own separate documentroot. I added a config file called: "api.example.com.conf" with this inside:
<VirtualHost *:80>
ServerAdmin admin@api.example.com
ServerName api.example.com
ServerAlias www.api.example.com
DocumentRoot /var/www/api.example.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.api.example.com [OR]
RewriteCond %{SERVER_NAME} =api.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I added the folder /var/www/api.example.com/html with an example index.html inside. I gave the folder the right permissions. After that I enabled the site with: "a2ensite api.example.com.conf" and restarted apache.
I added a new record to the example.com records. It is an A record with api.example.com and it redirects to the same ip as example.com because they are on the same server.
After doing all of this I expected that when I went to api.example.com that it would show me the example index.html that I had created but it did not. When I go to api.example.com it is the same thing as if I would go to example.com.
How do I make it so that api.example.com has its own document root that works correctly?
linux dns apache-http-server virtual-host
add a comment |
I am trying to configure a subdomain: api.example.com
(exapmle.com is replaced by my actual domain name)
I already had virtual hosts set up with 2 sites:
example.com and example.nl
they both had separate directories and where working correctly as separate sites.
Now I want to add api.example.com also with its own separate documentroot. I added a config file called: "api.example.com.conf" with this inside:
<VirtualHost *:80>
ServerAdmin admin@api.example.com
ServerName api.example.com
ServerAlias www.api.example.com
DocumentRoot /var/www/api.example.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.api.example.com [OR]
RewriteCond %{SERVER_NAME} =api.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I added the folder /var/www/api.example.com/html with an example index.html inside. I gave the folder the right permissions. After that I enabled the site with: "a2ensite api.example.com.conf" and restarted apache.
I added a new record to the example.com records. It is an A record with api.example.com and it redirects to the same ip as example.com because they are on the same server.
After doing all of this I expected that when I went to api.example.com that it would show me the example index.html that I had created but it did not. When I go to api.example.com it is the same thing as if I would go to example.com.
How do I make it so that api.example.com has its own document root that works correctly?
linux dns apache-http-server virtual-host
Did you reload Apache after adding this configuration?
– Daniel B
Jan 13 at 14:38
Yes, I did reload apache,
– C1rcu1tB04rd
Jan 13 at 14:55
Have you tried omitting the Rewrite rules?
– Anaksunaman
Jan 13 at 17:06
Yes, I have and I did not work.
– C1rcu1tB04rd
Jan 13 at 17:08
add a comment |
I am trying to configure a subdomain: api.example.com
(exapmle.com is replaced by my actual domain name)
I already had virtual hosts set up with 2 sites:
example.com and example.nl
they both had separate directories and where working correctly as separate sites.
Now I want to add api.example.com also with its own separate documentroot. I added a config file called: "api.example.com.conf" with this inside:
<VirtualHost *:80>
ServerAdmin admin@api.example.com
ServerName api.example.com
ServerAlias www.api.example.com
DocumentRoot /var/www/api.example.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.api.example.com [OR]
RewriteCond %{SERVER_NAME} =api.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I added the folder /var/www/api.example.com/html with an example index.html inside. I gave the folder the right permissions. After that I enabled the site with: "a2ensite api.example.com.conf" and restarted apache.
I added a new record to the example.com records. It is an A record with api.example.com and it redirects to the same ip as example.com because they are on the same server.
After doing all of this I expected that when I went to api.example.com that it would show me the example index.html that I had created but it did not. When I go to api.example.com it is the same thing as if I would go to example.com.
How do I make it so that api.example.com has its own document root that works correctly?
linux dns apache-http-server virtual-host
I am trying to configure a subdomain: api.example.com
(exapmle.com is replaced by my actual domain name)
I already had virtual hosts set up with 2 sites:
example.com and example.nl
they both had separate directories and where working correctly as separate sites.
Now I want to add api.example.com also with its own separate documentroot. I added a config file called: "api.example.com.conf" with this inside:
<VirtualHost *:80>
ServerAdmin admin@api.example.com
ServerName api.example.com
ServerAlias www.api.example.com
DocumentRoot /var/www/api.example.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.api.example.com [OR]
RewriteCond %{SERVER_NAME} =api.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I added the folder /var/www/api.example.com/html with an example index.html inside. I gave the folder the right permissions. After that I enabled the site with: "a2ensite api.example.com.conf" and restarted apache.
I added a new record to the example.com records. It is an A record with api.example.com and it redirects to the same ip as example.com because they are on the same server.
After doing all of this I expected that when I went to api.example.com that it would show me the example index.html that I had created but it did not. When I go to api.example.com it is the same thing as if I would go to example.com.
How do I make it so that api.example.com has its own document root that works correctly?
linux dns apache-http-server virtual-host
linux dns apache-http-server virtual-host
edited Jan 13 at 14:33
C1rcu1tB04rd
asked Jan 13 at 14:04
C1rcu1tB04rdC1rcu1tB04rd
11
11
Did you reload Apache after adding this configuration?
– Daniel B
Jan 13 at 14:38
Yes, I did reload apache,
– C1rcu1tB04rd
Jan 13 at 14:55
Have you tried omitting the Rewrite rules?
– Anaksunaman
Jan 13 at 17:06
Yes, I have and I did not work.
– C1rcu1tB04rd
Jan 13 at 17:08
add a comment |
Did you reload Apache after adding this configuration?
– Daniel B
Jan 13 at 14:38
Yes, I did reload apache,
– C1rcu1tB04rd
Jan 13 at 14:55
Have you tried omitting the Rewrite rules?
– Anaksunaman
Jan 13 at 17:06
Yes, I have and I did not work.
– C1rcu1tB04rd
Jan 13 at 17:08
Did you reload Apache after adding this configuration?
– Daniel B
Jan 13 at 14:38
Did you reload Apache after adding this configuration?
– Daniel B
Jan 13 at 14:38
Yes, I did reload apache,
– C1rcu1tB04rd
Jan 13 at 14:55
Yes, I did reload apache,
– C1rcu1tB04rd
Jan 13 at 14:55
Have you tried omitting the Rewrite rules?
– Anaksunaman
Jan 13 at 17:06
Have you tried omitting the Rewrite rules?
– Anaksunaman
Jan 13 at 17:06
Yes, I have and I did not work.
– C1rcu1tB04rd
Jan 13 at 17:08
Yes, I have and I did not work.
– C1rcu1tB04rd
Jan 13 at 17:08
add a comment |
1 Answer
1
active
oldest
votes
I am forcing all my domains to https but I did not yet have SSL setup for my new subdomain. I did have a virtual host for http://api.example.com, but my server does not allow HTTP so it redirected to https and because there was no virtual host for https://api.example.com it just redirected to the main domain.
Hi C1rcu1tB04rd, the answer section is intended for answers only please edit your question or use comments to provide supplements and delete this one.
– bummi
Jan 13 at 18:14
But that’s not a question update, it’s a proper answer. “There was no vhostapi.example.com
on*:443
”.
– Daniel B
Jan 13 at 19:35
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%2f1393781%2fapache-virtual-host-subdomain-not-working-correctly%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
I am forcing all my domains to https but I did not yet have SSL setup for my new subdomain. I did have a virtual host for http://api.example.com, but my server does not allow HTTP so it redirected to https and because there was no virtual host for https://api.example.com it just redirected to the main domain.
Hi C1rcu1tB04rd, the answer section is intended for answers only please edit your question or use comments to provide supplements and delete this one.
– bummi
Jan 13 at 18:14
But that’s not a question update, it’s a proper answer. “There was no vhostapi.example.com
on*:443
”.
– Daniel B
Jan 13 at 19:35
add a comment |
I am forcing all my domains to https but I did not yet have SSL setup for my new subdomain. I did have a virtual host for http://api.example.com, but my server does not allow HTTP so it redirected to https and because there was no virtual host for https://api.example.com it just redirected to the main domain.
Hi C1rcu1tB04rd, the answer section is intended for answers only please edit your question or use comments to provide supplements and delete this one.
– bummi
Jan 13 at 18:14
But that’s not a question update, it’s a proper answer. “There was no vhostapi.example.com
on*:443
”.
– Daniel B
Jan 13 at 19:35
add a comment |
I am forcing all my domains to https but I did not yet have SSL setup for my new subdomain. I did have a virtual host for http://api.example.com, but my server does not allow HTTP so it redirected to https and because there was no virtual host for https://api.example.com it just redirected to the main domain.
I am forcing all my domains to https but I did not yet have SSL setup for my new subdomain. I did have a virtual host for http://api.example.com, but my server does not allow HTTP so it redirected to https and because there was no virtual host for https://api.example.com it just redirected to the main domain.
answered Jan 13 at 17:53
C1rcu1tB04rdC1rcu1tB04rd
11
11
Hi C1rcu1tB04rd, the answer section is intended for answers only please edit your question or use comments to provide supplements and delete this one.
– bummi
Jan 13 at 18:14
But that’s not a question update, it’s a proper answer. “There was no vhostapi.example.com
on*:443
”.
– Daniel B
Jan 13 at 19:35
add a comment |
Hi C1rcu1tB04rd, the answer section is intended for answers only please edit your question or use comments to provide supplements and delete this one.
– bummi
Jan 13 at 18:14
But that’s not a question update, it’s a proper answer. “There was no vhostapi.example.com
on*:443
”.
– Daniel B
Jan 13 at 19:35
Hi C1rcu1tB04rd, the answer section is intended for answers only please edit your question or use comments to provide supplements and delete this one.
– bummi
Jan 13 at 18:14
Hi C1rcu1tB04rd, the answer section is intended for answers only please edit your question or use comments to provide supplements and delete this one.
– bummi
Jan 13 at 18:14
But that’s not a question update, it’s a proper answer. “There was no vhost
api.example.com
on *:443
”.– Daniel B
Jan 13 at 19:35
But that’s not a question update, it’s a proper answer. “There was no vhost
api.example.com
on *:443
”.– Daniel B
Jan 13 at 19:35
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%2f1393781%2fapache-virtual-host-subdomain-not-working-correctly%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
Did you reload Apache after adding this configuration?
– Daniel B
Jan 13 at 14:38
Yes, I did reload apache,
– C1rcu1tB04rd
Jan 13 at 14:55
Have you tried omitting the Rewrite rules?
– Anaksunaman
Jan 13 at 17:06
Yes, I have and I did not work.
– C1rcu1tB04rd
Jan 13 at 17:08