Map local IP 127.0.1.2 in different directory in Apache Server

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question
























    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?







    share|improve this question






















      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?







      share|improve this question












      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?









      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 3:41









      Sagaryal

      872211




      872211




















          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.






          share|improve this answer




















          • Thanks. ServerAlias method worked. First one, i didn't understand. Haha
            – Sagaryal
            Mar 24 at 13:59










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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






























          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.






          share|improve this answer




















          • Thanks. ServerAlias method worked. First one, i didn't understand. Haha
            – Sagaryal
            Mar 24 at 13:59














          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.






          share|improve this answer




















          • Thanks. ServerAlias method worked. First one, i didn't understand. Haha
            – Sagaryal
            Mar 24 at 13:59












          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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
















          • 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












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?