Does Apache keep holding a key file open when mod_ssl is enabled? - apache

I was testing my httpd config on centOS-like OS, and found a "wired" error AH02574: Init: Can't open server private key file in one of the VirtualHost, while another one doesn't produce any error.
In my config file, same SSL cert is referred by both (two) virtual hosts, of course is the private key file also shared. The httpd fail to start with this config. When I dig into the log, I found one virtual host (example.com) config does not produce any error, while the other vhost (sub.example.com, at latter lines in the ssl.conf) can't read the key file. I suspect this is due to the file was opened by the programme already, and hence stays on hold preventing it to be opened again. If this is the case, how should I solve it? An simple solution comes to my mind was to duplicate the key file, but I doubt for any security risk.
To give a better idea, below is a sample config:
<VirtualHost *:443>
ServerName example.com
# ... some other config
SSLCertificateFile "/path/to/ssl.crt"
SSLCertificateKeyFile "/path/to/ssl.key"
</VirtualHost>
<VirtualHost *:443>
ServerName sub.example.com
# ... some other config
SSLCertificateFile "/path/to/ssl.crt"
SSLCertificateKeyFile "/path/to/ssl.key"
</VirtualHost>

As per answer given by Jimmy, You can include sudo at the beginning of the command as below. I have also spent some 2 hours battling the same error but this helped me
sudo restorecon -RvF /etc/ssl/keyfile
After running the command, it should show as per image attached. Then you can restart the apache service
[1]: https://i.stack.imgur.com/uipI4.png

Although with a different problem, but This answer also resolves my problem!
Here is the solution provided by that answer:
restorecon -RvF /path/to/key_file

Related

virtualhost keeps redirecting to deleted alias information

I have a DigitalOcean droplet (i.e. a VPS server), with Ubuntu 14.04 and Apache 2.2.
I had 4 virtualhosts configured, with 4 different domains pointing to 4 different folders, no problem.
I needed to point a 5th domain (let's call it www.someshop.tld) containing a PrestaShop installation.
I added the following Alias to the apache2/sites-available/domain1.conf file so that www.domain1.tld/someshop would lead to www/prestashop, and it worked fine
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /www/directory1
Alias /someshop /www/prestashop #Alias line
</VirtualHost>
I did this as a temporary measure so I could have a working site publicly accessible, (so I could access www/prestashop publicly before I had configured www.someshop.tld DNS settings, 'A' record, Nameservers, etc.).
I now don't need to do this any more, so I deleted the Alias line from the .conf file so it looks like this:
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /www/directory1
</VirtualHost>
and added a new someshop.conf that looks like this:
<VirtualHost *:80>
ServerName www.someshop.tld
DocumentRoot /www/prestashop
</VirtualHost>
I then re-enabled both the .conf files in apache2/sites-enabled, and restarted apache with service apache2 restart.
However, when I go to www.someshop.tld, it continues to do a URL redirect to www.domain1.tld/prestashop (where there's this message: "Not Found, The requested URL /someshop was not found on this server").
I waited for a couple of hours before posting this question because I thought it might just be a "propagation" issue. So far it's still doing this.
My question: is this something that should clear up by waiting for it, or do I need to fix something else? E.g., is there some way for me to flush the old virtualhost Alias information?
Have you tried removing the site from apache config?
$ sudo a2dissite test.com.conf #Remove symlink
$ sudo service apache2 reload
This would remove the symlink. You can then create the symlink again with the proper configurations that you like.

How to change server name in apache

i want to change server name in apache. i know its easy as we can make changes in apache.cnf and httpd.cnf file. But i am tired after make changes in all file. i have checked all files and configuration but its not work only repdirect to another ip worked. So how can i change servername ??
<VirtualHost *:443>
ServerName xyz.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key.nopass
</VirtualHost>
Thanks for any help.
This can be achieved by installing Apache mod_security module.
After installation , open the Apache configuration file.
$ sudo vi /etc/apache2/apache2.conf #Debian/Ubuntu
$ vi /etc/httpd/conf/httpd.conf #RHEL/CentOS/Fedora
Now change or add these lines below (make sure to change Tech_Web to any other thing you want to appear to clients).
ServerTokens Full
SecServerSignature “Tech_Web”
Finally restart the web server.

NameVirtualHost Works on IP but not for ServerName?

I am a beginner to Apache and have been trying to create virtual hosts but I come across a very odd issue. When the site is requested using the IP defined in the configuration, the virtual host works perfectly but when the name of the server is used it does not work.
Here is the configuration file which is an included file:
Listen 80
NameVirtualHost 192.168.1.5
<VirtualHost 192.168.1.5>
ServerName host1.localhost
DocumentRoot "C:/Program Files (x86)/Apache Group/Apache2/virtualHost1"
</VirtualHost>
In the browser I go to 192.168.1.5 and the index file for the Virtual Host appears but when I go to host1.localhost it doesn't work.
Any help is very appreciated, good day to all.
First you should try to see if your computer resolve host1.localhost hostname.
May be just try to ping it in your console: ping host1.localhost
If your computer is unable to resolve host1.localhost, as I suppose, then try to add it in your hosts file.
Hint: you'll find hosts file in C:\Windows\System32\drivers\etc directory
What do you mean by "it doesn't work".
1)Check your DNS settings, do you have record for host1.localhost pointing to 192.168.1.5?
2)Try using ServerAlias also
3)Check if there is another declaration for hosts1.localhost (by another ServerAlias)
I guess the most likely reason is 1)

Error starting apache from terminal after removing MAMP

I removed MAMP recently.
When I try to start apache from Terminal using:
sudo apachectl -k restart
I am getting the message
Warning: DocumentRoot [usr/docs/dummy-host.example.com] does not exist.
First, make sure you're actually trying to execute the proper version of apachectl by issuing the following command:
which apachectl
(You don't want to see any MAMP references there).
Next, find your virtual hosts config (which is likely here if your MAMP references are gone)
/etc/apache2/extra/httpd-vhosts.conf
Make sure your virtual host definitions are good. (Sounds like you're referencing a bad one).
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Users/yourusername/Sites/mysite"
ServerName mysite.local
ErrorLog "/private/var/log/apache2/mysite-error_log"
CustomLog "/private/var/log/apache2/mysite-access_log" common
</VirtualHost>
(If you're using a custom server name other than 'localhost' like I've defined above, just be sure your /etc/hosts file is up to date with that entry like this:
127.0.0.1 mysite.local
Don't forget to restart apache!
sudo apachectl restart
You probably need to go to apache config file (something like etc/apache2/apache2.conf) and set it an existing document root directory. That is usually done with DocumentRoot directive in this file, or one of the included virtual host config definitions.
Make sure you comment out all the lines inside the /etc/apache2/extra/httpd-vhosts.conf file otherwise you will get the errors.

Apache SSL Configuration Error (SSL Connection Error)

I'm trying to configure Apache on my server to work with ssl, but everytime I visit my site, I get the following message in my browser:
SSL connection error.
Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.
The error message above seems to be native to Google Chrome. However, even though the messages are different, ssl for the site is not working on any browser.
Just some background on the situation: I am using Ubuntu 10.04 desktop edition.
I installed apache by installing zend server (it installed apache automatically).
I then installed openssl. Non-https pages work fine on the site.
I tried getting trial certificates from multiple certificate sites but nothing is working (same error).
I was previously hosting my site on another server on which ssl worked just fine. I also tried using the key and cert file from that server, but I got the same error.
The domain name and IP are still the same though. My SSLCertificateFile and SSLCertificateKeyFile are pointing to the correct directory and files.
I also do not have SSLVerifyClient enabled.
If anyone has any suggestions, it would be most appreciated.
I had the same problem as #User39604, and had to follow VARIOUS advices. Since he doesnt remember the precise path he followed, let me list my path:
check if you have SSL YES using <?php echo phpinfo();?>
if necessary
A. enable ssl on apache sudo a2enmod ssl
B. install openssl sudo apt-get install openssl
C. check if port 443 is open sudo netstat -lp
D. if necessary, change /etc/apache2/ports.conf, this works
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
NameVirtualHost *:443
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
acquire a key and a certificate by
A. paying a Certificating Authority (Comodo, GoDaddy, Verisign) for a pair
B. generating your own* - see below (testing purposes ONLY)
change your configuration (in ubuntu12 /etc/apache2/httpd.conf - default is an empty file) to include a proper <VirtualHost>
(replace MYSITE.COM as well as key and cert path/name to point to your certificate and key):
<VirtualHost _default_:443>
ServerName MYSITE.COM:443
SSLEngine on
SSLCertificateKeyFile /etc/apache2/ssl/MYSITE.COM.key
SSLCertificateFile /etc/apache2/ssl/MYSITE.COM.cert
ServerAdmin MYWEBGUY#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/errorSSL.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/accessSSL.log combined
</VirtualHost>
while many other virtualhost configs wil be available in /etc/apache2/sites-enabled/ and in /etc/apache2/sites-available/ it was /etc/apache2/httpd.conf that was CRUCIAL to solving all problems.
for further info:
http://wiki.vpslink.com/Enable_SSL_on_Apache2
http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html#selfcert
*generating your own certificate (self-signed) will result in a certificate whose authority the user's browser will not recognize. therefore, the browser will scream bloody murder and the user will have to "understand the risks" a dozen times before the browser actually opens up the page. so, it only works for testing purposes. having said that, this is the HOW-TO:
goto the apache folder (in ubuntu12 /etc/apache2/)
create a folder like ssl (or anything that works for you, the name is not a system requirement)
goto chosen directory /etc/apache2/ssl
run sudo openssl req -new -x509 -nodes -out MYSITE.COM.crt -keyout MYSITE.COM.key
use MYSITE.COM.crt and MYSITE.COM.key in your <VirtualHost> tag
name format is NOT under a strict system requirement, must be the same as the file :)
- names like 212-MYSITE.COM.crt, june2014-Godaddy-MYSITE.COM.crt should work.
I was getting the same error in chrome (and different one in Firefox, IE).
Also in error.log i was getting [error] [client cli.ent.ip.add] Invalid method in request \x16\x03
Following the instructions form this site I changed my configuration FROM:
<VirtualHost subdomain.domain.com:443>
ServerAdmin admin#domain.com
ServerName subdomain.domain.com
SSLEngine On
SSLCertificateFile conf/ssl/ssl.crt
SSLCertificateKeyFile conf/ssl/ssl.key
</VirtualHost>
TO:
<VirtualHost _default_:443>
ServerAdmin admin#domain.com
ServerName subdomain.domain.com
SSLEngine On
SSLCertificateFile conf/ssl/ssl.crt
SSLCertificateKeyFile conf/ssl/ssl.key
</VirtualHost>
Now it's working fine :)
Step to enable SSL correctly.
sudo a2enmod ssl
sudo apt-get install openssl
Configure the path of SSL certificates in your SSL config file (default-ssl.conf) that might be located in /etc/apache2/sites-available. I have stored certificates under /etc/apache2/ssl/
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/certificate.crt
SSLCertificateChainFile /etc/apache2/ssl/ca_bundle.crt
SSLCertificateKeyFile /etc/apache2/ssl/private.key
Enable SSL config file
sudo a2ensite default-ssl.conf
A common cause I wanted to suggest for this situation:
Sometimes a customer is running Skype, which is using port 443 without their realizing it. When they go to start Tomcat or Apache, it appears to start but cannot bind with port 443. This is the exact message that the user would receive in the browser. The fix is to stop what was running on port 443 and re-start the webserver so it can bind with port 443.
The customer can re-start Skype after starting the webserver, and Skype will detect that port 443 is in use and choose a different port to use.
#Make sure that you specify the port for both http and https ie.
NameVirtualHost:80
NameVirtualHost:443
#and
<VirtualHost *:80>
<VirtualHost *:443>
#mixing * and *:443 does not work it has to be *:80 and *:443
I got this problem and the solution was a bit silly.
I am using Cloudflare which acts as a proxy to my website. In order to be able to login via SSH, I added an entry to my /etc/hosts file so I didn't need to remember my server's IP address.
xxx.xx.xx.xxx example.com
So in my browser when I went to https://www.example.com, I was using the Cloudflare proxy, and when I went to to https://example.com I was going directly to the server. Because the Cloudflare setup doesn't require you to add the intermediate certificates, I was seeing this security exception in my browser when I went to https://example.com, but https://www.example.com was working.
The solution: remove the entry from my laptop's /etc/hosts file.
If this isn't your problem, I recommend using one of the many online SSL checker tools to try diagnose your problem.
I also recommend using ping to check the IP address being reported and check it against the IP address expected.
ping https://www.example.com/
Another very helpful SSL resource is the Mozilla SSL Configuration Generator. It can generate SSL configuration for you.
I didn't know what I was doing when I started changing the Apache configuration. I picked up bits and pieces thought it was working until I ran into the same problem you encountered, specifically Chrome having this error.
What I did was comment out all the site-specific directives that are used to configure SSL verification, confirmed that Chrome let me in, reviewed the documentation before directive before re-enabling one, and restarted Apache. By carefully going through these you ought to be able to figure out which one(s) are causing your problem.
In my case, I went from this:
SSLVerifyClient optional
SSLVerifyDepth 1
SSLOptions +StdEnvVars +StrictRequire
SSLRequireSSL On
to this
<Location /sessions>
SSLRequireSSL
SSLVerifyClient require
</Location>
As you can see I had a fair number of changes to get there.
I had this error when I first followed instructions to set up the default apache2 ssl configuration, by putting a symlink for /etc/apache2/sites-available/default-ssl in /etc/apache2/sites-enabled. I then subsequently tried to add another NameVirtualHost on port 443 in another configuration file, and started getting this error.
I fixed it by deleting the /etc/apache2/sites-enabled/default-ssl symlink, and then just having these lines in another config file (httpd.conf, which probably isn't good form, but worked):
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine on
SSLCertificateChainFile /etc/apache2/ssl/chain_file.crt
SSLCertificateFile /etc/apache2/ssl/site_certificate.crt
SSLCertificateKeyFile /etc/apache2/ssl/site_key.key
ServerName www.mywebsite.com
ServerAlias www.mywebsite.com
DocumentRoot /var/www/mywebsite_root/
</VirtualHost>
I encounter this problem, because I have <VirtualHost> defined both in httpd.conf and httpd-ssl.conf.
in httpd.conf, it's defined as
<VirtualHost localhost>
in httpd-ssl.conf, it's defined as
<VirtualHost _default_:443>
The following change solved this problem, add :80 in httpd.conf
<VirtualHost localhost:80>
This is what fixed it for me on Ubuntu.
Enabled the module: a2enmod ssl
Moved all cert related files to a folder /usr/local/ssl and made it world readable: chmod -R +r /usr/local/ssl
Changed <VirtualHost *:80> to <VirtualHost *:*> in my virtual host.
Added SSLEngine On before all other SSL directives in my virtual host.
If you set a pass phrase on the cert, Apache should prompt you for it on restart.
Similar to other answers, this error can be experienced when there are no sites configured to use SSL.
I had the error when I upgraded from Debian Wheezy to Debian Jessie. The new version of Apache requires a site configuration file ending in .conf. Because my configuration file didn't, it was being ignored, and there were no others configured to serve SSL connections.
I encountered this issue, also due to misconfiguration. I was using tomcat and in the server.xml had specified my connector as such:
<Connector port="17443" SSLEnabled="true"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keyAlias="wrong" keystorePass="secret"
keystoreFile="/ssl/right.jks" />
When i fixed it thusly:
<Connector port="17443" SSLEnabled="true"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keyAlias="right" keystorePass="secret"
keystoreFile="/ssl/right.jks" />
It worked as expected. In other words, verify that you not only have the right keystore, but that you have specified the correct alias underneath it. Thanks for the invaluable hint user396404.
I solved it by commenting out:
AcceptFilter https none
in httpd.conf
according to:
http://www.apachelounge.com/viewtopic.php?t=4461
It turns out that the SSL certificate was installed improperly. Re-installing it properly fixed the problem