How to disable non-SSL on Apache on only the host without disabling in virtual hosts?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
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:
- Run
a2enconf ssl
to enable SSL. - Run
a2ensite example.com
to
enable my domain. - Run
a2dissite 000-default
to disable the host
default site. - 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
bumped to the homepage by Community♦ 22 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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:
- Run
a2enconf ssl
to enable SSL. - Run
a2ensite example.com
to
enable my domain. - Run
a2dissite 000-default
to disable the host
default site. - 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
bumped to the homepage by Community♦ 22 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
add a comment |
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:
- Run
a2enconf ssl
to enable SSL. - Run
a2ensite example.com
to
enable my domain. - Run
a2dissite 000-default
to disable the host
default site. - 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
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:
- Run
a2enconf ssl
to enable SSL. - Run
a2ensite example.com
to
enable my domain. - Run
a2dissite 000-default
to disable the host
default site. - 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
apache2 ssl
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♦ 22 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♦ 22 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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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]
add a comment |
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
});
}
});
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%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
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]
add a comment |
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]
add a comment |
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]
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]
answered Oct 14 '16 at 1:48
tudortudor
3,11152048
3,11152048
add a comment |
add a comment |
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.
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%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
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
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