How to disable non-SSL on Apache on only the host without disabling in virtual hosts? ...

How to bypass password on Windows XP account?

Okay to merge included columns on otherwise identical indexes?

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

What causes the vertical darker bands in my photo?

Short Story with Cinderella as a Voo-doo Witch

How to call a function with default parameter through a pointer to function that is the return of another function?

How do pianists reach extremely loud dynamics?

Do I really need recursive chmod to restrict access to a folder?

Extract all GPU name, model and GPU ram

What is Arya's weapon design?

Single word antonym of "flightless"

When were vectors invented?

51k Euros annually for a family of 4 in Berlin: Is it enough?

How to react to hostile behavior from a senior developer?

In predicate logic, does existential quantification (∃) include universal quantification (∀), i.e. can 'some' imply 'all'?

Identifying polygons that intersect with another layer using QGIS?

Is it fair for a professor to grade us on the possession of past papers?

Why didn't this character "real die" when they blew their stack out in Altered Carbon?

Why do people hide their license plates in the EU?

List of Python versions

Why light coming from distant stars is not discreet?

What would be the ideal power source for a cybernetic eye?

Can an alien society believe that their star system is the universe?

Why am I getting the error "non-boolean type specified in a context where a condition is expected" for this request?



How to disable non-SSL on Apache on only the host without disabling in virtual hosts?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to disable non-ssl connection on Apache 2.2How to disable non-ssl connection on Apache 2.2Ubuntu Server Apache2 SSL virtual host not workingApache server virtual hosts not workingSNI not working ubuntu 14.04, multiple virtual host SSL on same IPApache2 - Virtual Host - Error 404 Not Found14.04 LTS with Apache and SSL as well as non-SSL site problemHow can I disable and enable SSL in Apache (without a command if possible)?Unable to access remotely (LAMP issue)Vhosts not working on Linux ServerApache2 - SSH - LetsEncrypt SSL - Certbot - Proxy - Manual Setup: How to achieve this?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















This is an extension (not a dupe) of How to disable non-ssl connection on Apache 2.2



Like the above question, I have:



Added a virtual host config /etc/apache2/sites-available/example.com.conf with an SSL cert.



<IfModule mod_ssl.c>
<VirtualHost example.com:443>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on

SSLCertificateFile /my/certs/mydomain.com.cert
SSLCertificateKeyFile /my/certs/mydomain.com.key
SSLCACertificateFile /my/certs/myprovider.ca

<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>


</VirtualHost>
</IfModule>


Then:




  1. Run a2enconf ssl to enable SSL.

  2. Run a2ensite example.com to
    enable my domain.

  3. Run a2dissite 000-default to disable the host
    default site.

  4. Run a2dissite default-ssl to disable the host
    default ssl site.


What should remain is only the site https://example.com/



However, I can also access http://example.com/ (non-SSL) which is an unexpected feature.



The other question's answers are to simply disable port 80 by commenting out Listen 80 but that means that other virtual hosts won't be able to specify port 80.



Why does Apache2 appear to accept port 80 when no virtual host specifies it and what is the correct way without disabling port 80 altogether?










share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • If your Apache listens on port 80, it will be accessible on port 80 by any name which resolves to your server's IP address. If you want to block access for a specific name, create a virtual host which directs to an error page.

    – fkraiem
    Oct 13 '16 at 7:04











  • It's not so much the name, but the fact that it responds on the host's IP and whatever name that matches to. (The reverse name, for example.) Maybe there's a setting that says not to respond to IP-only requests. I'll look into that. Thanks! :-)

    – tudor
    Oct 13 '16 at 22:12











  • "Maybe there's a setting that says not to respond to IP-only requests." No, there isn't.

    – fkraiem
    Oct 13 '16 at 22:19


















2















This is an extension (not a dupe) of How to disable non-ssl connection on Apache 2.2



Like the above question, I have:



Added a virtual host config /etc/apache2/sites-available/example.com.conf with an SSL cert.



<IfModule mod_ssl.c>
<VirtualHost example.com:443>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on

SSLCertificateFile /my/certs/mydomain.com.cert
SSLCertificateKeyFile /my/certs/mydomain.com.key
SSLCACertificateFile /my/certs/myprovider.ca

<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>


</VirtualHost>
</IfModule>


Then:




  1. Run a2enconf ssl to enable SSL.

  2. Run a2ensite example.com to
    enable my domain.

  3. Run a2dissite 000-default to disable the host
    default site.

  4. Run a2dissite default-ssl to disable the host
    default ssl site.


What should remain is only the site https://example.com/



However, I can also access http://example.com/ (non-SSL) which is an unexpected feature.



The other question's answers are to simply disable port 80 by commenting out Listen 80 but that means that other virtual hosts won't be able to specify port 80.



Why does Apache2 appear to accept port 80 when no virtual host specifies it and what is the correct way without disabling port 80 altogether?










share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • If your Apache listens on port 80, it will be accessible on port 80 by any name which resolves to your server's IP address. If you want to block access for a specific name, create a virtual host which directs to an error page.

    – fkraiem
    Oct 13 '16 at 7:04











  • It's not so much the name, but the fact that it responds on the host's IP and whatever name that matches to. (The reverse name, for example.) Maybe there's a setting that says not to respond to IP-only requests. I'll look into that. Thanks! :-)

    – tudor
    Oct 13 '16 at 22:12











  • "Maybe there's a setting that says not to respond to IP-only requests." No, there isn't.

    – fkraiem
    Oct 13 '16 at 22:19














2












2








2


1






This is an extension (not a dupe) of How to disable non-ssl connection on Apache 2.2



Like the above question, I have:



Added a virtual host config /etc/apache2/sites-available/example.com.conf with an SSL cert.



<IfModule mod_ssl.c>
<VirtualHost example.com:443>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on

SSLCertificateFile /my/certs/mydomain.com.cert
SSLCertificateKeyFile /my/certs/mydomain.com.key
SSLCACertificateFile /my/certs/myprovider.ca

<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>


</VirtualHost>
</IfModule>


Then:




  1. Run a2enconf ssl to enable SSL.

  2. Run a2ensite example.com to
    enable my domain.

  3. Run a2dissite 000-default to disable the host
    default site.

  4. Run a2dissite default-ssl to disable the host
    default ssl site.


What should remain is only the site https://example.com/



However, I can also access http://example.com/ (non-SSL) which is an unexpected feature.



The other question's answers are to simply disable port 80 by commenting out Listen 80 but that means that other virtual hosts won't be able to specify port 80.



Why does Apache2 appear to accept port 80 when no virtual host specifies it and what is the correct way without disabling port 80 altogether?










share|improve this question
















This is an extension (not a dupe) of How to disable non-ssl connection on Apache 2.2



Like the above question, I have:



Added a virtual host config /etc/apache2/sites-available/example.com.conf with an SSL cert.



<IfModule mod_ssl.c>
<VirtualHost example.com:443>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on

SSLCertificateFile /my/certs/mydomain.com.cert
SSLCertificateKeyFile /my/certs/mydomain.com.key
SSLCACertificateFile /my/certs/myprovider.ca

<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>


</VirtualHost>
</IfModule>


Then:




  1. Run a2enconf ssl to enable SSL.

  2. Run a2ensite example.com to
    enable my domain.

  3. Run a2dissite 000-default to disable the host
    default site.

  4. Run a2dissite default-ssl to disable the host
    default ssl site.


What should remain is only the site https://example.com/



However, I can also access http://example.com/ (non-SSL) which is an unexpected feature.



The other question's answers are to simply disable port 80 by commenting out Listen 80 but that means that other virtual hosts won't be able to specify port 80.



Why does Apache2 appear to accept port 80 when no virtual host specifies it and what is the correct way without disabling port 80 altogether?







apache2 ssl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:23









Community

1




1










asked Oct 13 '16 at 6:48









tudortudor

3,11152048




3,11152048





bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • If your Apache listens on port 80, it will be accessible on port 80 by any name which resolves to your server's IP address. If you want to block access for a specific name, create a virtual host which directs to an error page.

    – fkraiem
    Oct 13 '16 at 7:04











  • It's not so much the name, but the fact that it responds on the host's IP and whatever name that matches to. (The reverse name, for example.) Maybe there's a setting that says not to respond to IP-only requests. I'll look into that. Thanks! :-)

    – tudor
    Oct 13 '16 at 22:12











  • "Maybe there's a setting that says not to respond to IP-only requests." No, there isn't.

    – fkraiem
    Oct 13 '16 at 22:19



















  • If your Apache listens on port 80, it will be accessible on port 80 by any name which resolves to your server's IP address. If you want to block access for a specific name, create a virtual host which directs to an error page.

    – fkraiem
    Oct 13 '16 at 7:04











  • It's not so much the name, but the fact that it responds on the host's IP and whatever name that matches to. (The reverse name, for example.) Maybe there's a setting that says not to respond to IP-only requests. I'll look into that. Thanks! :-)

    – tudor
    Oct 13 '16 at 22:12











  • "Maybe there's a setting that says not to respond to IP-only requests." No, there isn't.

    – fkraiem
    Oct 13 '16 at 22:19

















If your Apache listens on port 80, it will be accessible on port 80 by any name which resolves to your server's IP address. If you want to block access for a specific name, create a virtual host which directs to an error page.

– fkraiem
Oct 13 '16 at 7:04





If your Apache listens on port 80, it will be accessible on port 80 by any name which resolves to your server's IP address. If you want to block access for a specific name, create a virtual host which directs to an error page.

– fkraiem
Oct 13 '16 at 7:04













It's not so much the name, but the fact that it responds on the host's IP and whatever name that matches to. (The reverse name, for example.) Maybe there's a setting that says not to respond to IP-only requests. I'll look into that. Thanks! :-)

– tudor
Oct 13 '16 at 22:12





It's not so much the name, but the fact that it responds on the host's IP and whatever name that matches to. (The reverse name, for example.) Maybe there's a setting that says not to respond to IP-only requests. I'll look into that. Thanks! :-)

– tudor
Oct 13 '16 at 22:12













"Maybe there's a setting that says not to respond to IP-only requests." No, there isn't.

– fkraiem
Oct 13 '16 at 22:19





"Maybe there's a setting that says not to respond to IP-only requests." No, there isn't.

– fkraiem
Oct 13 '16 at 22:19










1 Answer
1






active

oldest

votes


















0














This is almost an answer in that it doesn't leak information out of port 80 by accident:



Create a file in /etc/apache2/sites-available/forbidipaccess.conf with contents:



NameVirtualHost *:80
<VirtualHost *:80>
<Location />
Order deny,allow
Deny from all
</Location>
</VirtualHost>


Then run:
sudo a2ensite forbidipaccess and
sudo service apache2 reload



This doesn't block the IP as such, but it does issue a 403 Forbidden response if there isn't a config with that specific domain name as its ServerName or ServerAlias.



If we wanted to be super-nice and didn't like the "Forbidden" message, we could alternatively use an Apache Rewrite to return a 301/2/3 which would forward the user to the equivalent SSL, e.g.



RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R=301,L]





share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    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%2faskubuntu.com%2fquestions%2f836370%2fhow-to-disable-non-ssl-on-apache-on-only-the-host-without-disabling-in-virtual-h%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









    0














    This is almost an answer in that it doesn't leak information out of port 80 by accident:



    Create a file in /etc/apache2/sites-available/forbidipaccess.conf with contents:



    NameVirtualHost *:80
    <VirtualHost *:80>
    <Location />
    Order deny,allow
    Deny from all
    </Location>
    </VirtualHost>


    Then run:
    sudo a2ensite forbidipaccess and
    sudo service apache2 reload



    This doesn't block the IP as such, but it does issue a 403 Forbidden response if there isn't a config with that specific domain name as its ServerName or ServerAlias.



    If we wanted to be super-nice and didn't like the "Forbidden" message, we could alternatively use an Apache Rewrite to return a 301/2/3 which would forward the user to the equivalent SSL, e.g.



    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R=301,L]





    share|improve this answer




























      0














      This is almost an answer in that it doesn't leak information out of port 80 by accident:



      Create a file in /etc/apache2/sites-available/forbidipaccess.conf with contents:



      NameVirtualHost *:80
      <VirtualHost *:80>
      <Location />
      Order deny,allow
      Deny from all
      </Location>
      </VirtualHost>


      Then run:
      sudo a2ensite forbidipaccess and
      sudo service apache2 reload



      This doesn't block the IP as such, but it does issue a 403 Forbidden response if there isn't a config with that specific domain name as its ServerName or ServerAlias.



      If we wanted to be super-nice and didn't like the "Forbidden" message, we could alternatively use an Apache Rewrite to return a 301/2/3 which would forward the user to the equivalent SSL, e.g.



      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R=301,L]





      share|improve this answer


























        0












        0








        0







        This is almost an answer in that it doesn't leak information out of port 80 by accident:



        Create a file in /etc/apache2/sites-available/forbidipaccess.conf with contents:



        NameVirtualHost *:80
        <VirtualHost *:80>
        <Location />
        Order deny,allow
        Deny from all
        </Location>
        </VirtualHost>


        Then run:
        sudo a2ensite forbidipaccess and
        sudo service apache2 reload



        This doesn't block the IP as such, but it does issue a 403 Forbidden response if there isn't a config with that specific domain name as its ServerName or ServerAlias.



        If we wanted to be super-nice and didn't like the "Forbidden" message, we could alternatively use an Apache Rewrite to return a 301/2/3 which would forward the user to the equivalent SSL, e.g.



        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R=301,L]





        share|improve this answer













        This is almost an answer in that it doesn't leak information out of port 80 by accident:



        Create a file in /etc/apache2/sites-available/forbidipaccess.conf with contents:



        NameVirtualHost *:80
        <VirtualHost *:80>
        <Location />
        Order deny,allow
        Deny from all
        </Location>
        </VirtualHost>


        Then run:
        sudo a2ensite forbidipaccess and
        sudo service apache2 reload



        This doesn't block the IP as such, but it does issue a 403 Forbidden response if there isn't a config with that specific domain name as its ServerName or ServerAlias.



        If we wanted to be super-nice and didn't like the "Forbidden" message, we could alternatively use an Apache Rewrite to return a 301/2/3 which would forward the user to the equivalent SSL, e.g.



        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R=301,L]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 14 '16 at 1:48









        tudortudor

        3,11152048




        3,11152048






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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%2faskubuntu.com%2fquestions%2f836370%2fhow-to-disable-non-ssl-on-apache-on-only-the-host-without-disabling-in-virtual-h%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

            Why do type traits not work with types in namespace scope?What are POD types in C++?Why can templates only be...

            Will tsunami waves travel forever if there was no land?Why do tsunami waves begin with the water flowing away...

            Simple Scan not detecting my scanner (Brother DCP-7055W)Brother MFC-L2700DW printer can print, can't...