Apache2 - Configure two websites, one with ip/port, one with domain
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am hosting two websites on a Raspberry Pi Apache2 server.
One website has a domain name, while the second site doesn't. I want to access the second one with the server IP on same port but without a domain name.
So to access the first one, I would type domainname.com
and for the second 1.2.3.4
.
With this current setup, both the domain name AND the IP go to the first website.
Here are my two .conf
files:
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost _default_:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What should I put in ServerName
for the second website? Since it doesn't have a domain and I'm just accessing it by IP?
I also tried using _default_
but it didn't seem to do anything?
apache-http-server virtual-host
add a comment |
I am hosting two websites on a Raspberry Pi Apache2 server.
One website has a domain name, while the second site doesn't. I want to access the second one with the server IP on same port but without a domain name.
So to access the first one, I would type domainname.com
and for the second 1.2.3.4
.
With this current setup, both the domain name AND the IP go to the first website.
Here are my two .conf
files:
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost _default_:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What should I put in ServerName
for the second website? Since it doesn't have a domain and I'm just accessing it by IP?
I also tried using _default_
but it didn't seem to do anything?
apache-http-server virtual-host
You can't access 2 different web servers on the same port and IP address. Possible XY problem
– DavidPostill♦
Mar 9 at 13:32
@DavidPostill But you can have two websites on same IP and port number. Its theServerName
in the HTTP request that allows Apache to distinguish which one the client wants.
– Francesco Gorini
Mar 10 at 0:50
@Anaksunaman Thanks a lot, i do not express myself well in english still. Appreciate it a lot.
– Francesco Gorini
Mar 10 at 0:51
add a comment |
I am hosting two websites on a Raspberry Pi Apache2 server.
One website has a domain name, while the second site doesn't. I want to access the second one with the server IP on same port but without a domain name.
So to access the first one, I would type domainname.com
and for the second 1.2.3.4
.
With this current setup, both the domain name AND the IP go to the first website.
Here are my two .conf
files:
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost _default_:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What should I put in ServerName
for the second website? Since it doesn't have a domain and I'm just accessing it by IP?
I also tried using _default_
but it didn't seem to do anything?
apache-http-server virtual-host
I am hosting two websites on a Raspberry Pi Apache2 server.
One website has a domain name, while the second site doesn't. I want to access the second one with the server IP on same port but without a domain name.
So to access the first one, I would type domainname.com
and for the second 1.2.3.4
.
With this current setup, both the domain name AND the IP go to the first website.
Here are my two .conf
files:
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost _default_:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What should I put in ServerName
for the second website? Since it doesn't have a domain and I'm just accessing it by IP?
I also tried using _default_
but it didn't seem to do anything?
apache-http-server virtual-host
apache-http-server virtual-host
edited Mar 10 at 1:33
Anaksunaman
5,75321423
5,75321423
asked Mar 9 at 7:19
Francesco GoriniFrancesco Gorini
81
81
You can't access 2 different web servers on the same port and IP address. Possible XY problem
– DavidPostill♦
Mar 9 at 13:32
@DavidPostill But you can have two websites on same IP and port number. Its theServerName
in the HTTP request that allows Apache to distinguish which one the client wants.
– Francesco Gorini
Mar 10 at 0:50
@Anaksunaman Thanks a lot, i do not express myself well in english still. Appreciate it a lot.
– Francesco Gorini
Mar 10 at 0:51
add a comment |
You can't access 2 different web servers on the same port and IP address. Possible XY problem
– DavidPostill♦
Mar 9 at 13:32
@DavidPostill But you can have two websites on same IP and port number. Its theServerName
in the HTTP request that allows Apache to distinguish which one the client wants.
– Francesco Gorini
Mar 10 at 0:50
@Anaksunaman Thanks a lot, i do not express myself well in english still. Appreciate it a lot.
– Francesco Gorini
Mar 10 at 0:51
You can't access 2 different web servers on the same port and IP address. Possible XY problem
– DavidPostill♦
Mar 9 at 13:32
You can't access 2 different web servers on the same port and IP address. Possible XY problem
– DavidPostill♦
Mar 9 at 13:32
@DavidPostill But you can have two websites on same IP and port number. Its the
ServerName
in the HTTP request that allows Apache to distinguish which one the client wants.– Francesco Gorini
Mar 10 at 0:50
@DavidPostill But you can have two websites on same IP and port number. Its the
ServerName
in the HTTP request that allows Apache to distinguish which one the client wants.– Francesco Gorini
Mar 10 at 0:50
@Anaksunaman Thanks a lot, i do not express myself well in english still. Appreciate it a lot.
– Francesco Gorini
Mar 10 at 0:51
@Anaksunaman Thanks a lot, i do not express myself well in english still. Appreciate it a lot.
– Francesco Gorini
Mar 10 at 0:51
add a comment |
1 Answer
1
active
oldest
votes
It's likely that you need to "reverse" the entries for your websites. Per the current Apache 2.4 documentation on Name-based Virtual Host Support:
If no matching
ServerName
orServerAlias
is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.
So your configuration files (in order) should be:
<VirtualHost *:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Note that the _default_
entry should be unnecessary. Any request that doesn't match raspberrypi
or domainname.com
/www.domainname.com
(such as 1.2.3.4
) should be matched to the first virtual host (raspberrypi
).
Thank you a lot. How would i change the order if those 2 where in separate files?
– Francesco Gorini
Mar 10 at 0:47
I solved this by renaming the one i wanted to be default to come earlier alphabetically. So1mainsite.conf
and2secondsite.conf
– Francesco Gorini
Mar 10 at 1:25
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%2f1412606%2fapache2-configure-two-websites-one-with-ip-port-one-with-domain%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
It's likely that you need to "reverse" the entries for your websites. Per the current Apache 2.4 documentation on Name-based Virtual Host Support:
If no matching
ServerName
orServerAlias
is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.
So your configuration files (in order) should be:
<VirtualHost *:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Note that the _default_
entry should be unnecessary. Any request that doesn't match raspberrypi
or domainname.com
/www.domainname.com
(such as 1.2.3.4
) should be matched to the first virtual host (raspberrypi
).
Thank you a lot. How would i change the order if those 2 where in separate files?
– Francesco Gorini
Mar 10 at 0:47
I solved this by renaming the one i wanted to be default to come earlier alphabetically. So1mainsite.conf
and2secondsite.conf
– Francesco Gorini
Mar 10 at 1:25
add a comment |
It's likely that you need to "reverse" the entries for your websites. Per the current Apache 2.4 documentation on Name-based Virtual Host Support:
If no matching
ServerName
orServerAlias
is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.
So your configuration files (in order) should be:
<VirtualHost *:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Note that the _default_
entry should be unnecessary. Any request that doesn't match raspberrypi
or domainname.com
/www.domainname.com
(such as 1.2.3.4
) should be matched to the first virtual host (raspberrypi
).
Thank you a lot. How would i change the order if those 2 where in separate files?
– Francesco Gorini
Mar 10 at 0:47
I solved this by renaming the one i wanted to be default to come earlier alphabetically. So1mainsite.conf
and2secondsite.conf
– Francesco Gorini
Mar 10 at 1:25
add a comment |
It's likely that you need to "reverse" the entries for your websites. Per the current Apache 2.4 documentation on Name-based Virtual Host Support:
If no matching
ServerName
orServerAlias
is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.
So your configuration files (in order) should be:
<VirtualHost *:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Note that the _default_
entry should be unnecessary. Any request that doesn't match raspberrypi
or domainname.com
/www.domainname.com
(such as 1.2.3.4
) should be matched to the first virtual host (raspberrypi
).
It's likely that you need to "reverse" the entries for your websites. Per the current Apache 2.4 documentation on Name-based Virtual Host Support:
If no matching
ServerName
orServerAlias
is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.
So your configuration files (in order) should be:
<VirtualHost *:80>
ServerName raspberrypi
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domainname.com
ServerAlias www.domainname.com
ServerAdmin domainname@gmail.com
DocumentRoot /var/www/domainname.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Note that the _default_
entry should be unnecessary. Any request that doesn't match raspberrypi
or domainname.com
/www.domainname.com
(such as 1.2.3.4
) should be matched to the first virtual host (raspberrypi
).
edited Mar 10 at 1:31
answered Mar 9 at 20:06
AnaksunamanAnaksunaman
5,75321423
5,75321423
Thank you a lot. How would i change the order if those 2 where in separate files?
– Francesco Gorini
Mar 10 at 0:47
I solved this by renaming the one i wanted to be default to come earlier alphabetically. So1mainsite.conf
and2secondsite.conf
– Francesco Gorini
Mar 10 at 1:25
add a comment |
Thank you a lot. How would i change the order if those 2 where in separate files?
– Francesco Gorini
Mar 10 at 0:47
I solved this by renaming the one i wanted to be default to come earlier alphabetically. So1mainsite.conf
and2secondsite.conf
– Francesco Gorini
Mar 10 at 1:25
Thank you a lot. How would i change the order if those 2 where in separate files?
– Francesco Gorini
Mar 10 at 0:47
Thank you a lot. How would i change the order if those 2 where in separate files?
– Francesco Gorini
Mar 10 at 0:47
I solved this by renaming the one i wanted to be default to come earlier alphabetically. So
1mainsite.conf
and 2secondsite.conf
– Francesco Gorini
Mar 10 at 1:25
I solved this by renaming the one i wanted to be default to come earlier alphabetically. So
1mainsite.conf
and 2secondsite.conf
– Francesco Gorini
Mar 10 at 1:25
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%2f1412606%2fapache2-configure-two-websites-one-with-ip-port-one-with-domain%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
You can't access 2 different web servers on the same port and IP address. Possible XY problem
– DavidPostill♦
Mar 9 at 13:32
@DavidPostill But you can have two websites on same IP and port number. Its the
ServerName
in the HTTP request that allows Apache to distinguish which one the client wants.– Francesco Gorini
Mar 10 at 0:50
@Anaksunaman Thanks a lot, i do not express myself well in english still. Appreciate it a lot.
– Francesco Gorini
Mar 10 at 0:51