Map local IP 127.0.1.2 in different directory in Apache Server

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
In my localhost (Apache Server), I have two VirtualHost in port 80 pointing to different directory.
Here is my two conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/myuser/project_1/
ErrorLog $APACHE_LOG_DIR/error.log
CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName project2
DocumentRoot /home/myuser/project_2/
ErrorLog $APACHE_LOG_DIR/error.log
CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>
And in my /etc/hosts file:
127.0.0.1 localhost
127.0.1.2 project2
Now when I type http://localhost it maps to project_1 directory and for http://project2/ it maps to project_2 directory. Things are fine here but if I type 127.0.1.2 it always maps to first project_1 instead of project_2 directory i.e it maps to localhost instead of project2 url.
Why is this? How I can do such reverse mapping?
linux apache-httpd apache-virtualhost
add a comment |Â
up vote
0
down vote
favorite
In my localhost (Apache Server), I have two VirtualHost in port 80 pointing to different directory.
Here is my two conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/myuser/project_1/
ErrorLog $APACHE_LOG_DIR/error.log
CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName project2
DocumentRoot /home/myuser/project_2/
ErrorLog $APACHE_LOG_DIR/error.log
CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>
And in my /etc/hosts file:
127.0.0.1 localhost
127.0.1.2 project2
Now when I type http://localhost it maps to project_1 directory and for http://project2/ it maps to project_2 directory. Things are fine here but if I type 127.0.1.2 it always maps to first project_1 instead of project_2 directory i.e it maps to localhost instead of project2 url.
Why is this? How I can do such reverse mapping?
linux apache-httpd apache-virtualhost
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In my localhost (Apache Server), I have two VirtualHost in port 80 pointing to different directory.
Here is my two conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/myuser/project_1/
ErrorLog $APACHE_LOG_DIR/error.log
CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName project2
DocumentRoot /home/myuser/project_2/
ErrorLog $APACHE_LOG_DIR/error.log
CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>
And in my /etc/hosts file:
127.0.0.1 localhost
127.0.1.2 project2
Now when I type http://localhost it maps to project_1 directory and for http://project2/ it maps to project_2 directory. Things are fine here but if I type 127.0.1.2 it always maps to first project_1 instead of project_2 directory i.e it maps to localhost instead of project2 url.
Why is this? How I can do such reverse mapping?
linux apache-httpd apache-virtualhost
In my localhost (Apache Server), I have two VirtualHost in port 80 pointing to different directory.
Here is my two conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/myuser/project_1/
ErrorLog $APACHE_LOG_DIR/error.log
CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName project2
DocumentRoot /home/myuser/project_2/
ErrorLog $APACHE_LOG_DIR/error.log
CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>
And in my /etc/hosts file:
127.0.0.1 localhost
127.0.1.2 project2
Now when I type http://localhost it maps to project_1 directory and for http://project2/ it maps to project_2 directory. Things are fine here but if I type 127.0.1.2 it always maps to first project_1 instead of project_2 directory i.e it maps to localhost instead of project2 url.
Why is this? How I can do such reverse mapping?
linux apache-httpd apache-virtualhost
asked Mar 23 at 3:41
Sagaryal
872211
872211
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
In your virtual host configurations, you are using name based virtual hosts as you specify ServerName. This means that a configuration would only load when the "Host" header in the client request matches. The default behavior of Apache when it cannot match the requested host with any configured virtual hosts is to load the first configured virtual host it can find.
There are many options to get the right content, one is to adjust the "Host" header in your request to match the ServerName you are trying to reach. Another would be to add the IP address as a ServerAlias or you could switch to IP based virtual hosts and configure things that way.
Thanks. ServerAlias method worked. First one, i didn't understand. Haha
â Sagaryal
Mar 24 at 13:59
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
In your virtual host configurations, you are using name based virtual hosts as you specify ServerName. This means that a configuration would only load when the "Host" header in the client request matches. The default behavior of Apache when it cannot match the requested host with any configured virtual hosts is to load the first configured virtual host it can find.
There are many options to get the right content, one is to adjust the "Host" header in your request to match the ServerName you are trying to reach. Another would be to add the IP address as a ServerAlias or you could switch to IP based virtual hosts and configure things that way.
Thanks. ServerAlias method worked. First one, i didn't understand. Haha
â Sagaryal
Mar 24 at 13:59
add a comment |Â
up vote
4
down vote
accepted
In your virtual host configurations, you are using name based virtual hosts as you specify ServerName. This means that a configuration would only load when the "Host" header in the client request matches. The default behavior of Apache when it cannot match the requested host with any configured virtual hosts is to load the first configured virtual host it can find.
There are many options to get the right content, one is to adjust the "Host" header in your request to match the ServerName you are trying to reach. Another would be to add the IP address as a ServerAlias or you could switch to IP based virtual hosts and configure things that way.
Thanks. ServerAlias method worked. First one, i didn't understand. Haha
â Sagaryal
Mar 24 at 13:59
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
In your virtual host configurations, you are using name based virtual hosts as you specify ServerName. This means that a configuration would only load when the "Host" header in the client request matches. The default behavior of Apache when it cannot match the requested host with any configured virtual hosts is to load the first configured virtual host it can find.
There are many options to get the right content, one is to adjust the "Host" header in your request to match the ServerName you are trying to reach. Another would be to add the IP address as a ServerAlias or you could switch to IP based virtual hosts and configure things that way.
In your virtual host configurations, you are using name based virtual hosts as you specify ServerName. This means that a configuration would only load when the "Host" header in the client request matches. The default behavior of Apache when it cannot match the requested host with any configured virtual hosts is to load the first configured virtual host it can find.
There are many options to get the right content, one is to adjust the "Host" header in your request to match the ServerName you are trying to reach. Another would be to add the IP address as a ServerAlias or you could switch to IP based virtual hosts and configure things that way.
answered Mar 23 at 4:11
GracefulRestart
74917
74917
Thanks. ServerAlias method worked. First one, i didn't understand. Haha
â Sagaryal
Mar 24 at 13:59
add a comment |Â
Thanks. ServerAlias method worked. First one, i didn't understand. Haha
â Sagaryal
Mar 24 at 13:59
Thanks. ServerAlias method worked. First one, i didn't understand. Haha
â Sagaryal
Mar 24 at 13:59
Thanks. ServerAlias method worked. First one, i didn't understand. Haha
â Sagaryal
Mar 24 at 13:59
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432984%2fmap-local-ip-127-0-1-2-in-different-directory-in-apache-server%23new-answer', 'question_page');
);
Post as a guest
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
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
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