LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-15-2015, 05:16 PM   #1
Altiris
Member
 
Registered: Mar 2013
Posts: 556

Rep: Reputation: Disabled
HTTPS Rewrite is not working


Alright, Slackware 14.1 install. I have httpd running and named. I have made sure the required modules are enabled, as well as configured and created the required SSL files for httpd to use https. I am trying to make it so typing my test domain, slackdomain.com will redirect to https (I know this works because this is how it is configured on my centos box)

/etc/httpd/httpd.conf
Code:
/etc/httpd/httpd.conf
ServerRoot "/usr"
Listen 80
LoadModule authn_file_module lib64/httpd/modules/mod_authn_file.so
LoadModule authn_core_module lib64/httpd/modules/mod_authn_core.so
LoadModule authz_host_module lib64/httpd/modules/mod_authz_host.so
LoadModule authz_groupfile_module lib64/httpd/modules/mod_authz_groupfile.so
LoadModule authz_user_module lib64/httpd/modules/mod_authz_user.so
LoadModule authz_core_module lib64/httpd/modules/mod_authz_core.so
LoadModule access_compat_module lib64/httpd/modules/mod_access_compat.so
LoadModule auth_basic_module lib64/httpd/modules/mod_auth_basic.so
LoadModule reqtimeout_module lib64/httpd/modules/mod_reqtimeout.so
LoadModule filter_module lib64/httpd/modules/mod_filter.so
LoadModule mime_module lib64/httpd/modules/mod_mime.so
LoadModule log_config_module lib64/httpd/modules/mod_log_config.so
LoadModule env_module lib64/httpd/modules/mod_env.so
LoadModule headers_module lib64/httpd/modules/mod_headers.so
LoadModule setenvif_module lib64/httpd/modules/mod_setenvif.so
LoadModule version_module lib64/httpd/modules/mod_version.so
LoadModule proxy_module lib64/httpd/modules/mod_proxy.so
LoadModule proxy_connect_module lib64/httpd/modules/mod_proxy_connect.so
LoadModule proxy_ftp_module lib64/httpd/modules/mod_proxy_ftp.so
LoadModule proxy_http_module lib64/httpd/modules/mod_proxy_http.so
LoadModule proxy_fcgi_module lib64/httpd/modules/mod_proxy_fcgi.so
LoadModule proxy_scgi_module lib64/httpd/modules/mod_proxy_scgi.so
LoadModule proxy_wstunnel_module lib64/httpd/modules/mod_proxy_wstunnel.so
LoadModule proxy_ajp_module lib64/httpd/modules/mod_proxy_ajp.so
LoadModule proxy_express_module lib64/httpd/modules/mod_proxy_express.so
LoadModule lbmethod_byrequests_module lib64/httpd/modules/mod_lbmethod_byrequests.so
LoadModule lbmethod_bytraffic_module lib64/httpd/modules/mod_lbmethod_bytraffic.so
LoadModule lbmethod_bybusyness_module lib64/httpd/modules/mod_lbmethod_bybusyness.so
LoadModule mpm_event_module lib64/httpd/modules/mod_mpm_event.so
LoadModule unixd_module lib64/httpd/modules/mod_unixd.so
LoadModule status_module lib64/httpd/modules/mod_status.so
LoadModule autoindex_module lib64/httpd/modules/mod_autoindex.so
LoadModule dir_module lib64/httpd/modules/mod_dir.so
LoadModule alias_module lib64/httpd/modules/mod_alias.so
LoadModule rewrite_module lib64/httpd/modules/mod_rewrite.so
<IfModule unixd_module>
User apache
Group apache
</IfModule>
ServerAdmin you@example.com
ServerName www.slackdomain.com:80
<Directory />
    AllowOverride none
    Require all denied
</Directory>
DocumentRoot "/srv/www/slackdomain.com"
<Directory "/srv/www/slackdomain.com">
    Options Indexes FollowSymLinks
</Directory>
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
<Files ".ht*">
    Require all denied
</Files>
ErrorLog "/var/log/httpd/error_log"
LogLevel warn
<IfModule log_config_module>  
    LogFormat "h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>

      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
</IfModule>
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/srv/httpd/cgi-bin/"
</IfModule>
<IfModule cgid_module>

</IfModule>
<Directory "/srv/httpd/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
<IfModule mime_module>
</IfModule>
<IfModule proxy_html_module>
Include /etc/httpd/extra/proxy-html.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
/etc/httpd/extra/httpd-ssl.conf
Code:
httpd-autoindex.conf           httpd-mpm.conf
httpd-dav.conf                 httpd-multilang-errordoc.conf
httpd-default.conf             httpd-ssl.conf
httpd-info.conf                httpd-ssl.conf.orig
httpd-languages.conf           httpd-userdir.conf
httpd-manual.conf              httpd-vhosts.conf
httpd-manual.conf.orig         proxy-html.conf
root@slacktest:~# grep -vE '^#|^;|^$' /etc/httpd/extra/httpd-ssl.conf
Listen 443
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:/var/run/ssl_scache(512000)"
SSLSessionCacheTimeout  300
<VirtualHost _default_:443>
DocumentRoot "/srv/httpd/htdocs"
ServerName www.example.com:443
ServerAdmin you@example.com
ErrorLog "/var/log/httpd/error_log"
TransferLog "/var/log/httpd/access_log"
SSLEngine on
SSLCertificateFile "/etc/httpd/server.crt"
SSLCertificateKeyFile "/etc/httpd/server.key"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/srv/httpd/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0
CustomLog "/var/log/httpd/ssl_request_log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
/etc/httpd/extra/httpd-vhosts.conf
Code:
NameVirtualHost *:80
<VirtualHost *:80>
	RewriteEngine on
	RewriteCond %{HTTPS} off
	RewriteRule (.*) https://%{HTTP_HOST}:443%{REQUEST_URI}	
	Redirect permanent / https://slackdomain.com/
	ServerName www.slackdomain.com:80
	DocumentRoot /srv/www/slackdomain.com
	ServerAdmin info@slackdomain.com
	ErrorLog /var/log/httpd/slackdomain.com-error_log
	CustomLog /var/log/httpd/slackdomain.com-access_log common
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
	ServerName www.slackdomain.com:443
	ServerAdmin info@slackdomain.com
	DocumentRoot /srv/www/slackdomain.com/
	Redirect permanent / https://slackdomain.com/
	SSLEngine On
	SSLCertificateFile /etc/ssl/certs/server.crt
	SSLCertificateKeyFile /etc/ssl/private/server.key
	<Directory /srv/www/slackdomain.com>
	AllowOverride All
	</Directory>
	ErrorLog /var/log/httpd/slackdomain.com-error_log
	CustomLog /var/log/http/slackdomain.com-access_log common
</VirtualHost>
 
Old 06-15-2015, 05:55 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by Altiris View Post
I know this works because this is how it is configured on my centos box
Same Apache version? I ask because some rules work on one version but not on another one (that's probably why many webmasters are reluctant to uprade). I have been bitten by that trying to cook a .htaccess that works locally _and_ c/o my host.

Last edited by Didier Spaier; 06-16-2015 at 10:59 AM. Reason: Typo corrected.
 
Old 06-15-2015, 10:48 PM   #3
Altiris
Member
 
Registered: Mar 2013
Posts: 556

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Didier Spaier View Post
Same Apache version? I ask because some rules work on one version but not on another one (that's probably why many webmasters are reluctant to uprade). I have been bitten by that trying to cook a .htaccess that work locally _and_ c/o my host.
The version on CentOS 6.6 is 2.2.15 and on Slackware it is 2.4.12....pretty big difference. I would imagine something like mod_rewrite wouldn't' change though.

I picked this up, https://wiki.apache.org/httpd/RewriteHTTPToHTTPS and I am to place it in a .htaccess file...ill work a bit more on it tomorrow morning and see if I can get it done.

EDIT: I also just found this...which is really similar to my current Virtualhosts config but doing https://mydomain or https://127.0.0.1 does not bring me to page. http://httpd.apache.org/docs/2.4/ssl/ssl_howto.html

Last edited by Altiris; 06-15-2015 at 10:49 PM.
 
Old 06-15-2015, 11:00 PM   #4
Altiris
Member
 
Registered: Mar 2013
Posts: 556

Original Poster
Rep: Reputation: Disabled
I tried putting those things from the link in a .htaccess file in /srv/www/slackdomain.com and I made sure in /etc/httpd/httpd.conf the AllowOverride All was set in the /srv/www/slackdomain.com directory but nothing.
 
Old 06-16-2015, 10:55 AM   #5
tdos20
Member
 
Registered: Aug 2006
Location: London
Distribution: Slackware
Posts: 132

Rep: Reputation: 39
You shouldn't need the :443 on the end of the rewrite condition:
Quote:
RewriteRule (.*) https://%{HTTP_HOST}:443%{REQUEST_URI}
try
Code:
RewriteCond %{HTTPS} !=on
RewriteRule https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
You probably want a server alias in there after server name also
Code:
ServerAlias  slackdomain.com
So something like this:
Code:
NameVirtualHost *:80
<VirtualHost *:80>
	RewriteEngine on
	RewriteCond %{HTTPS} off
	RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}	
	Redirect permanent / https://slackdomain.com/
	ServerName www.slackdomain.com
        ServerAlias slackdomain.com
	DocumentRoot /srv/www/slackdomain.com
	ServerAdmin info@slackdomain.com
	ErrorLog /var/log/httpd/slackdomain.com-error_log
	CustomLog /var/log/httpd/slackdomain.com-access_log common
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
	ServerName www.slackdomain.com
        ServerAlias slackdomain.com
	ServerAdmin info@slackdomain.com
	DocumentRoot /srv/www/slackdomain.com/
	SSLEngine On
	SSLCertificateFile /etc/ssl/certs/server.crt
	SSLCertificateKeyFile /etc/ssl/private/server.key
	<Directory /srv/www/slackdomain.com>
	AllowOverride All
	</Directory>
	ErrorLog /var/log/httpd/slackdomain.com-error_log
	CustomLog /var/log/http/slackdomain.com-access_log common
</VirtualHost>
You can also do lots of debugging with mod rewrite - careful not to fill up the hard drive with it!
http://httpd.apache.org/docs/current...d_rewrite.html
 
Old 06-25-2015, 04:39 PM   #6
Altiris
Member
 
Registered: Mar 2013
Posts: 556

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tdos20 View Post
You shouldn't need the :443 on the end of the rewrite condition:

try
Code:
RewriteCond {HTTPS} !=on
RewriteRule https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
You probably want a server alias in there after server name also
Code:
ServerAlias  slackdomain.com
So something like this:
Code:
NameVirtualHost *:80
<VirtualHost *:80>
	RewriteEngine on
	RewriteCond %{HTTPS} off
	RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}	
	Redirect permanent / https://slackdomain.com/
	ServerName www.slackdomain.com
        ServerAlias slackdomain.com
	DocumentRoot /srv/www/slackdomain.com
	ServerAdmin info@slackdomain.com
	ErrorLog /var/log/httpd/slackdomain.com-error_log
	CustomLog /var/log/httpd/slackdomain.com-access_log common
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
	ServerName www.slackdomain.com
        ServerAlias slackdomain.com
	ServerAdmin info@slackdomain.com
	DocumentRoot /srv/www/slackdomain.com/
	SSLEngine On
	SSLCertificateFile /etc/ssl/certs/server.crt
	SSLCertificateKeyFile /etc/ssl/private/server.key
	<Directory /srv/www/slackdomain.com>
	AllowOverride All
	</Directory>
	ErrorLog /var/log/httpd/slackdomain.com-error_log
	CustomLog /var/log/http/slackdomain.com-access_log common
</VirtualHost>
You can also do lots of debugging with mod rewrite - careful not to fill up the hard drive with it!
http://httpd.apache.org/docs/current...d_rewrite.html
Sadly this did not help at all. I tried putting the 443 Virtualhost entry in either httpd-vhosts.conf and/or httpd-ssl.conf and still nothing. I uncommented the virtualhost example in httpd-ssl.conf and still nothing. One thing I noticed is that if the web server is running if I try typing my IP into firefox 10.0.2.15, it redirects/forces https. When stopping httpd/apache it no longer forces https (but nothing loads obviously because its off) so this means the rewrite thingy is somewhat working in my Virtualhost 80 entry in httpd-vhosts.conf ....hmm

EDIT: Reading http://www.slackwiki.com/SSL#Verifying_and_debugging and I tried out some of the debugging commands. I am getting
Code:
Error opening server certificate private key file server.pem
140203644364480:error:02001002:system library:fopen:No such file or directory:bss_file.c:391:fopen('server.pem','r')
140203644364480:error:20074002:BIO routines:FILE_CTRL:system lib:bss_file.c:393:
unable to load server certificate private key file
When running openssl s_server -accept 443 -www or openssl s_client -connect localhost:443 the file server.pem does not even exist on my system, dont know why its calling out for it.
EDIT2: Simply trying to do https://10.0.2.15 does not work so HTTPS itself is not working...

Last edited by Altiris; 06-25-2015 at 05:51 PM.
 
Old 06-26-2015, 03:38 AM   #7
tdos20
Member
 
Registered: Aug 2006
Location: London
Distribution: Slackware
Posts: 132

Rep: Reputation: 39
Can you post the output of /var/log/httpd/slackdomain.com-error_log ?
 
Old 06-28-2015, 08:02 PM   #8
Altiris
Member
 
Registered: Mar 2013
Posts: 556

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tdos20 View Post
Can you post the output of /var/log/httpd/slackdomain.com-error_log ?
It's completely empty, nothing is getting logged there. It's still getting logged only to the default access and error log files.
 
Old 06-28-2015, 08:19 PM   #9
BrZ
Member
 
Registered: Apr 2009
Distribution: Slackware
Posts: 543

Rep: Reputation: 121Reputation: 121
/etc/httpd/extra/httpd-ssl.conf:
ServerName www.example.com:443 ???
 
Old 06-29-2015, 04:05 AM   #10
tdos20
Member
 
Registered: Aug 2006
Location: London
Distribution: Slackware
Posts: 132

Rep: Reputation: 39
Can you post the contents of those logs? maybe to pastebin then a link.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache rewrite rule for https linson_85 Linux - Server 7 03-26-2015 12:30 PM
Rewrite for https in apache server elok Linux - Server 4 11-10-2010 02:30 AM
Apache2 rewrite http to https gabsik Linux - Networking 3 10-26-2006 12:18 PM
Apache Rewrite Not Working mikeyt_333 Linux - General 1 05-20-2003 05:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration