Running two websites with two subdomains httpd





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have a domain example.com with two subdomains: website.example.com and cloud.example.com. I set an A-Record for both of them to my server's IP address.



my server is a VPS with centos7 and has two directories below /var/www/html/ for each of the domains:





  • /var/www/html/website.example.com/ contains all wordpress files


  • /var/www/html/cloud/ contains all files for ownCloud.


I enhanced my httpd.conf to contain:



Listen 80
Listen 81

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www/html/website.example.com
ServerName www.website.example.com
</VirtualHost>

NameVirtualHost *:81
<VirtualHost *:81>
DocumentRoot /var/www/html/cloud
ServerName www.cloud.example.com
</VirtualHost>


Now, when I restart httpd and run wget i get the following responses:





  • my.vps.ip.address -> response from wordpress site


  • my.vps.ip.address:80 -> response from wordpress site


  • my.vps.ip.address:81 -> response from cloud site


  • website.example.com -> response from wordpress site


  • cloud.example.com -> response from wordpress site.


This results to the browser experience -> When i enter website.example.com in my browser I get on my wordpress site. But when I enter cloud.example.com I also get on my wordpress site instead of the owncloud site.



What am I missing?










share|improve this question































    1















    I have a domain example.com with two subdomains: website.example.com and cloud.example.com. I set an A-Record for both of them to my server's IP address.



    my server is a VPS with centos7 and has two directories below /var/www/html/ for each of the domains:





    • /var/www/html/website.example.com/ contains all wordpress files


    • /var/www/html/cloud/ contains all files for ownCloud.


    I enhanced my httpd.conf to contain:



    Listen 80
    Listen 81

    # Listen for virtual host requests on all IP addresses
    NameVirtualHost *:80

    <VirtualHost *:80>
    DocumentRoot /var/www/html/website.example.com
    ServerName www.website.example.com
    </VirtualHost>

    NameVirtualHost *:81
    <VirtualHost *:81>
    DocumentRoot /var/www/html/cloud
    ServerName www.cloud.example.com
    </VirtualHost>


    Now, when I restart httpd and run wget i get the following responses:





    • my.vps.ip.address -> response from wordpress site


    • my.vps.ip.address:80 -> response from wordpress site


    • my.vps.ip.address:81 -> response from cloud site


    • website.example.com -> response from wordpress site


    • cloud.example.com -> response from wordpress site.


    This results to the browser experience -> When i enter website.example.com in my browser I get on my wordpress site. But when I enter cloud.example.com I also get on my wordpress site instead of the owncloud site.



    What am I missing?










    share|improve this question



























      1












      1








      1








      I have a domain example.com with two subdomains: website.example.com and cloud.example.com. I set an A-Record for both of them to my server's IP address.



      my server is a VPS with centos7 and has two directories below /var/www/html/ for each of the domains:





      • /var/www/html/website.example.com/ contains all wordpress files


      • /var/www/html/cloud/ contains all files for ownCloud.


      I enhanced my httpd.conf to contain:



      Listen 80
      Listen 81

      # Listen for virtual host requests on all IP addresses
      NameVirtualHost *:80

      <VirtualHost *:80>
      DocumentRoot /var/www/html/website.example.com
      ServerName www.website.example.com
      </VirtualHost>

      NameVirtualHost *:81
      <VirtualHost *:81>
      DocumentRoot /var/www/html/cloud
      ServerName www.cloud.example.com
      </VirtualHost>


      Now, when I restart httpd and run wget i get the following responses:





      • my.vps.ip.address -> response from wordpress site


      • my.vps.ip.address:80 -> response from wordpress site


      • my.vps.ip.address:81 -> response from cloud site


      • website.example.com -> response from wordpress site


      • cloud.example.com -> response from wordpress site.


      This results to the browser experience -> When i enter website.example.com in my browser I get on my wordpress site. But when I enter cloud.example.com I also get on my wordpress site instead of the owncloud site.



      What am I missing?










      share|improve this question
















      I have a domain example.com with two subdomains: website.example.com and cloud.example.com. I set an A-Record for both of them to my server's IP address.



      my server is a VPS with centos7 and has two directories below /var/www/html/ for each of the domains:





      • /var/www/html/website.example.com/ contains all wordpress files


      • /var/www/html/cloud/ contains all files for ownCloud.


      I enhanced my httpd.conf to contain:



      Listen 80
      Listen 81

      # Listen for virtual host requests on all IP addresses
      NameVirtualHost *:80

      <VirtualHost *:80>
      DocumentRoot /var/www/html/website.example.com
      ServerName www.website.example.com
      </VirtualHost>

      NameVirtualHost *:81
      <VirtualHost *:81>
      DocumentRoot /var/www/html/cloud
      ServerName www.cloud.example.com
      </VirtualHost>


      Now, when I restart httpd and run wget i get the following responses:





      • my.vps.ip.address -> response from wordpress site


      • my.vps.ip.address:80 -> response from wordpress site


      • my.vps.ip.address:81 -> response from cloud site


      • website.example.com -> response from wordpress site


      • cloud.example.com -> response from wordpress site.


      This results to the browser experience -> When i enter website.example.com in my browser I get on my wordpress site. But when I enter cloud.example.com I also get on my wordpress site instead of the owncloud site.



      What am I missing?







      apache-2.4 virtualhost subdomain






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 15 at 9:06









      Gerald Schneider

      6,71532647




      6,71532647










      asked Feb 15 at 7:34









      talbxtalbx

      83




      83






















          1 Answer
          1






          active

          oldest

          votes


















          4














          You've set your ServerName to www.cloud.example.com, but try to access it with cloud.example.com. Also you forgot the port 81.



          Either set it to cloud.example.com or add an ServerAlias cloud.example.com.



          You don't need to set the cloud.example.com on a different port. Apache is perfectly capable of handling different VirtualHosts on the same port. Just leave it on port 80.



          It should look like this:



          Listen 80
          # Listen 81
          # Just stay on port 80, don't make it more complicated for the clients

          # Listen for virtual host requests on all IP addresses
          # NameVirtualHost *:80
          # This is not needed anymore with Apache 2.4

          <VirtualHost *:80>
          DocumentRoot /var/www/html/website.example.com
          ServerName website.example.com
          ServerAlias www.website.example.com
          </VirtualHost>

          <VirtualHost *:80>
          DocumentRoot /var/www/html/cloud
          ServerName cloud.example.com
          </VirtualHost>





          share|improve this answer


























          • I adapted my httpd conf according to your comment. now the wget for cloud.example.com does return the correct response. Only problem is that I cannot get the correct response using chrome. cloud.example.com in chrome still leads to website.example.com. Entering the IP in chrome leads to website.example.com

            – talbx
            Feb 15 at 8:22













          • Did you restart apache? Did you clear your browser cache? If you access apache with a hostname that is not configured (like you do when you use the IP) apache uses the first listed VirtualHost. See my answer here for details.

            – Gerald Schneider
            Feb 15 at 8:32











          • I added an example configuration to the answer

            – Gerald Schneider
            Feb 15 at 8:35











          • I now use the full configuration provided by you. still I can only access the website.example.com , while cloud.example.com gets redirected. I assume, the problem lays in my DNS configuration. I setup the two subdomains in my domain provider, though my server is hosted somewhere else and probably the linking between the host /server names isnt working out, but actually i have no clue how to fix that. As of now both have the same A-Record -> Ip address of the vps. Does my vps need some dns configuration or something?

            – talbx
            Feb 15 at 8:44













          • Redirection does not happen via DNS. If you get an actual redirect (the URL in your browser changes from cloud to website) you have something else configured in your Apache that you haven't shown yet.

            – Gerald Schneider
            Feb 15 at 8:53














          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "2"
          };
          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f954067%2frunning-two-websites-with-two-subdomains-httpd%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









          4














          You've set your ServerName to www.cloud.example.com, but try to access it with cloud.example.com. Also you forgot the port 81.



          Either set it to cloud.example.com or add an ServerAlias cloud.example.com.



          You don't need to set the cloud.example.com on a different port. Apache is perfectly capable of handling different VirtualHosts on the same port. Just leave it on port 80.



          It should look like this:



          Listen 80
          # Listen 81
          # Just stay on port 80, don't make it more complicated for the clients

          # Listen for virtual host requests on all IP addresses
          # NameVirtualHost *:80
          # This is not needed anymore with Apache 2.4

          <VirtualHost *:80>
          DocumentRoot /var/www/html/website.example.com
          ServerName website.example.com
          ServerAlias www.website.example.com
          </VirtualHost>

          <VirtualHost *:80>
          DocumentRoot /var/www/html/cloud
          ServerName cloud.example.com
          </VirtualHost>





          share|improve this answer


























          • I adapted my httpd conf according to your comment. now the wget for cloud.example.com does return the correct response. Only problem is that I cannot get the correct response using chrome. cloud.example.com in chrome still leads to website.example.com. Entering the IP in chrome leads to website.example.com

            – talbx
            Feb 15 at 8:22













          • Did you restart apache? Did you clear your browser cache? If you access apache with a hostname that is not configured (like you do when you use the IP) apache uses the first listed VirtualHost. See my answer here for details.

            – Gerald Schneider
            Feb 15 at 8:32











          • I added an example configuration to the answer

            – Gerald Schneider
            Feb 15 at 8:35











          • I now use the full configuration provided by you. still I can only access the website.example.com , while cloud.example.com gets redirected. I assume, the problem lays in my DNS configuration. I setup the two subdomains in my domain provider, though my server is hosted somewhere else and probably the linking between the host /server names isnt working out, but actually i have no clue how to fix that. As of now both have the same A-Record -> Ip address of the vps. Does my vps need some dns configuration or something?

            – talbx
            Feb 15 at 8:44













          • Redirection does not happen via DNS. If you get an actual redirect (the URL in your browser changes from cloud to website) you have something else configured in your Apache that you haven't shown yet.

            – Gerald Schneider
            Feb 15 at 8:53


















          4














          You've set your ServerName to www.cloud.example.com, but try to access it with cloud.example.com. Also you forgot the port 81.



          Either set it to cloud.example.com or add an ServerAlias cloud.example.com.



          You don't need to set the cloud.example.com on a different port. Apache is perfectly capable of handling different VirtualHosts on the same port. Just leave it on port 80.



          It should look like this:



          Listen 80
          # Listen 81
          # Just stay on port 80, don't make it more complicated for the clients

          # Listen for virtual host requests on all IP addresses
          # NameVirtualHost *:80
          # This is not needed anymore with Apache 2.4

          <VirtualHost *:80>
          DocumentRoot /var/www/html/website.example.com
          ServerName website.example.com
          ServerAlias www.website.example.com
          </VirtualHost>

          <VirtualHost *:80>
          DocumentRoot /var/www/html/cloud
          ServerName cloud.example.com
          </VirtualHost>





          share|improve this answer


























          • I adapted my httpd conf according to your comment. now the wget for cloud.example.com does return the correct response. Only problem is that I cannot get the correct response using chrome. cloud.example.com in chrome still leads to website.example.com. Entering the IP in chrome leads to website.example.com

            – talbx
            Feb 15 at 8:22













          • Did you restart apache? Did you clear your browser cache? If you access apache with a hostname that is not configured (like you do when you use the IP) apache uses the first listed VirtualHost. See my answer here for details.

            – Gerald Schneider
            Feb 15 at 8:32











          • I added an example configuration to the answer

            – Gerald Schneider
            Feb 15 at 8:35











          • I now use the full configuration provided by you. still I can only access the website.example.com , while cloud.example.com gets redirected. I assume, the problem lays in my DNS configuration. I setup the two subdomains in my domain provider, though my server is hosted somewhere else and probably the linking between the host /server names isnt working out, but actually i have no clue how to fix that. As of now both have the same A-Record -> Ip address of the vps. Does my vps need some dns configuration or something?

            – talbx
            Feb 15 at 8:44













          • Redirection does not happen via DNS. If you get an actual redirect (the URL in your browser changes from cloud to website) you have something else configured in your Apache that you haven't shown yet.

            – Gerald Schneider
            Feb 15 at 8:53
















          4












          4








          4







          You've set your ServerName to www.cloud.example.com, but try to access it with cloud.example.com. Also you forgot the port 81.



          Either set it to cloud.example.com or add an ServerAlias cloud.example.com.



          You don't need to set the cloud.example.com on a different port. Apache is perfectly capable of handling different VirtualHosts on the same port. Just leave it on port 80.



          It should look like this:



          Listen 80
          # Listen 81
          # Just stay on port 80, don't make it more complicated for the clients

          # Listen for virtual host requests on all IP addresses
          # NameVirtualHost *:80
          # This is not needed anymore with Apache 2.4

          <VirtualHost *:80>
          DocumentRoot /var/www/html/website.example.com
          ServerName website.example.com
          ServerAlias www.website.example.com
          </VirtualHost>

          <VirtualHost *:80>
          DocumentRoot /var/www/html/cloud
          ServerName cloud.example.com
          </VirtualHost>





          share|improve this answer















          You've set your ServerName to www.cloud.example.com, but try to access it with cloud.example.com. Also you forgot the port 81.



          Either set it to cloud.example.com or add an ServerAlias cloud.example.com.



          You don't need to set the cloud.example.com on a different port. Apache is perfectly capable of handling different VirtualHosts on the same port. Just leave it on port 80.



          It should look like this:



          Listen 80
          # Listen 81
          # Just stay on port 80, don't make it more complicated for the clients

          # Listen for virtual host requests on all IP addresses
          # NameVirtualHost *:80
          # This is not needed anymore with Apache 2.4

          <VirtualHost *:80>
          DocumentRoot /var/www/html/website.example.com
          ServerName website.example.com
          ServerAlias www.website.example.com
          </VirtualHost>

          <VirtualHost *:80>
          DocumentRoot /var/www/html/cloud
          ServerName cloud.example.com
          </VirtualHost>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 15 at 8:35

























          answered Feb 15 at 8:00









          Gerald SchneiderGerald Schneider

          6,71532647




          6,71532647













          • I adapted my httpd conf according to your comment. now the wget for cloud.example.com does return the correct response. Only problem is that I cannot get the correct response using chrome. cloud.example.com in chrome still leads to website.example.com. Entering the IP in chrome leads to website.example.com

            – talbx
            Feb 15 at 8:22













          • Did you restart apache? Did you clear your browser cache? If you access apache with a hostname that is not configured (like you do when you use the IP) apache uses the first listed VirtualHost. See my answer here for details.

            – Gerald Schneider
            Feb 15 at 8:32











          • I added an example configuration to the answer

            – Gerald Schneider
            Feb 15 at 8:35











          • I now use the full configuration provided by you. still I can only access the website.example.com , while cloud.example.com gets redirected. I assume, the problem lays in my DNS configuration. I setup the two subdomains in my domain provider, though my server is hosted somewhere else and probably the linking between the host /server names isnt working out, but actually i have no clue how to fix that. As of now both have the same A-Record -> Ip address of the vps. Does my vps need some dns configuration or something?

            – talbx
            Feb 15 at 8:44













          • Redirection does not happen via DNS. If you get an actual redirect (the URL in your browser changes from cloud to website) you have something else configured in your Apache that you haven't shown yet.

            – Gerald Schneider
            Feb 15 at 8:53





















          • I adapted my httpd conf according to your comment. now the wget for cloud.example.com does return the correct response. Only problem is that I cannot get the correct response using chrome. cloud.example.com in chrome still leads to website.example.com. Entering the IP in chrome leads to website.example.com

            – talbx
            Feb 15 at 8:22













          • Did you restart apache? Did you clear your browser cache? If you access apache with a hostname that is not configured (like you do when you use the IP) apache uses the first listed VirtualHost. See my answer here for details.

            – Gerald Schneider
            Feb 15 at 8:32











          • I added an example configuration to the answer

            – Gerald Schneider
            Feb 15 at 8:35











          • I now use the full configuration provided by you. still I can only access the website.example.com , while cloud.example.com gets redirected. I assume, the problem lays in my DNS configuration. I setup the two subdomains in my domain provider, though my server is hosted somewhere else and probably the linking between the host /server names isnt working out, but actually i have no clue how to fix that. As of now both have the same A-Record -> Ip address of the vps. Does my vps need some dns configuration or something?

            – talbx
            Feb 15 at 8:44













          • Redirection does not happen via DNS. If you get an actual redirect (the URL in your browser changes from cloud to website) you have something else configured in your Apache that you haven't shown yet.

            – Gerald Schneider
            Feb 15 at 8:53



















          I adapted my httpd conf according to your comment. now the wget for cloud.example.com does return the correct response. Only problem is that I cannot get the correct response using chrome. cloud.example.com in chrome still leads to website.example.com. Entering the IP in chrome leads to website.example.com

          – talbx
          Feb 15 at 8:22







          I adapted my httpd conf according to your comment. now the wget for cloud.example.com does return the correct response. Only problem is that I cannot get the correct response using chrome. cloud.example.com in chrome still leads to website.example.com. Entering the IP in chrome leads to website.example.com

          – talbx
          Feb 15 at 8:22















          Did you restart apache? Did you clear your browser cache? If you access apache with a hostname that is not configured (like you do when you use the IP) apache uses the first listed VirtualHost. See my answer here for details.

          – Gerald Schneider
          Feb 15 at 8:32





          Did you restart apache? Did you clear your browser cache? If you access apache with a hostname that is not configured (like you do when you use the IP) apache uses the first listed VirtualHost. See my answer here for details.

          – Gerald Schneider
          Feb 15 at 8:32













          I added an example configuration to the answer

          – Gerald Schneider
          Feb 15 at 8:35





          I added an example configuration to the answer

          – Gerald Schneider
          Feb 15 at 8:35













          I now use the full configuration provided by you. still I can only access the website.example.com , while cloud.example.com gets redirected. I assume, the problem lays in my DNS configuration. I setup the two subdomains in my domain provider, though my server is hosted somewhere else and probably the linking between the host /server names isnt working out, but actually i have no clue how to fix that. As of now both have the same A-Record -> Ip address of the vps. Does my vps need some dns configuration or something?

          – talbx
          Feb 15 at 8:44







          I now use the full configuration provided by you. still I can only access the website.example.com , while cloud.example.com gets redirected. I assume, the problem lays in my DNS configuration. I setup the two subdomains in my domain provider, though my server is hosted somewhere else and probably the linking between the host /server names isnt working out, but actually i have no clue how to fix that. As of now both have the same A-Record -> Ip address of the vps. Does my vps need some dns configuration or something?

          – talbx
          Feb 15 at 8:44















          Redirection does not happen via DNS. If you get an actual redirect (the URL in your browser changes from cloud to website) you have something else configured in your Apache that you haven't shown yet.

          – Gerald Schneider
          Feb 15 at 8:53







          Redirection does not happen via DNS. If you get an actual redirect (the URL in your browser changes from cloud to website) you have something else configured in your Apache that you haven't shown yet.

          – Gerald Schneider
          Feb 15 at 8:53




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Server Fault!


          • 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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f954067%2frunning-two-websites-with-two-subdomains-httpd%23new-answer', 'question_page');
          }
          );

          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







          Popular posts from this blog

          Human spaceflight

          Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

          張江高科駅