2

I am currently running CentOS which hosts my web and gitlab server and a windows machine that is hosting a subsonic server. Currently, my ip points to the CentOS but does not redirect correctly. I am able to access / but unable to access any other sites with the subdomain despite the settings I have made so I would like to know where I am going wrong and how to rectify the issue. Is it also possible that when people enter http://git.example.com that it will automatically be redirected to https://git.example.com? Thanks in advance!

NameVirtualHost *:80
#This should lead to subsonic server
<VirtualHost *>
    ServerName music.company.com
    ServerAlias www.music.company.com
    ProxyRequests Off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyErrorOverride On
    ProxyPass / http://192.168.1.14:6060/
    ProxyPassReverse / http://192.168.1.14:6060/
    <Location />
        Order allow,deny
        Allow from all
    </Location> 
</VirtualHost>

Gitlab.conf

LoadModule ssl_module modules/mod_ssl.so
SSLSessionCache "shmcb:logs/ssl_scache(512000)"

<VirtualHost *:443>
  SSLEngine on
  #strong encryption ciphers only
  #see ciphers(1) http://www.openssl.org/docs/apps/ciphers.html
  SSLCipherSuite SSLv3:TLSv1:+HIGH:!SSLv2:!MD5:!MEDIUM:!LOW:!EXP:!ADH:!eNULL:!aNULL
  SSLCertificateFile    /etc/pki/tls/certs/ca.crt
  SSLCertificateKeyFile /etc/pki/tls/private/ca.key
  SSLCACertificateFile  /etc/pki/tls/certs/ca.crt

  ServerName 127.0.0.1
  ServerSignature Off

  ProxyPreserveHost On

  <Location />
    Order deny,allow
    Allow from all

    ProxyPassReverse http://127.0.0.1:8080
    ProxyPassReverse http://127.0.0.1/
  </Location>

  #apache equivalent of nginx try files
  # http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files
  # http://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab
  RewriteEngine on
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA]
  RequestHeader set X_FORWARDED_PROTO 'https'

  # needed for downloading attachments
  DocumentRoot /home/git/gitlab/public

  #Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up.
  ErrorDocument 404 /404.html
  ErrorDocument 422 /422.html
  ErrorDocument 500 /500.html
  ErrorDocument 503 /deploy.html

  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
  ErrorLog  /var/log/httpd/logs/gitlab.example.com_error.log
  CustomLog /var/log/httpd/logs/gitlab.example.com_forwarded.log common_forwarded
  CustomLog /var/log/httpd/logs/gitlab.example.com_access.log combined env=!dontlog
  CustomLog /var/log/httpd/logs/gitlab.example.com.log combined

</VirtualHost>

3 Answers 3

1

You have a mismatch between

NameVirtualHost *:80

and

<VirtualHost *>

You need to change the VirtualHost to be the same as NameVirtualHost, i.e.

<VirtualHost *:80>

As for the redirect, vic's answer should help - if not, have a look at Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask

6
  • shouldn't i be using proxy instead of mod_rewrite? when should i be using proxy instead?
    – Hong Yi
    Mar 27, 2014 at 14:33
  • You can use both. Use mod_rewrite for the redirect, and mod_proy to access the actual content.
    – Jenny D
    Mar 27, 2014 at 15:18
  • i am a bit confused with this. what redirect and proxy should be done? shouldn't the virtualhost:80 be listening for the subdomain already? then proxy to access the actual content?
    – Hong Yi
    Mar 27, 2014 at 15:24
  • 1
    You asked how to redirect http://git.example.com to https://git.example.com. You do this by having a virtualhost *:80 with ServerName git.example.com and within that virtualhost you use mod_rewrite to redirect to https://git.example.com.
    – Jenny D
    Mar 27, 2014 at 15:58
  • how about the proxy of music.comapny.com to the other server? I can't seem to get it working. :/
    – Hong Yi
    Mar 27, 2014 at 16:17
0

Use these rules they worked for me:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) (https)://%{HTTP_HOST}%{REQUEST_URI} 
RewriteEngine On
RewriteRule ^apache-redirect-http-to-https\.html$ (https)://www.yoursite.com/apache-redirect-http-to-https.html [R=301,L] 

Note: remove () with https link. These are my configs:

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName mysite.example.com
   DocumentRoot /usr/local/apache2/htdocs 
   Redirect permanent / https://mysite.example.com/
</VirtualHost>
<VirtualHost _default_:443>
   ServerName mysite.example.com
   DocumentRoot /usr/local/apache2/htdocs
   SSLEngine On
   # etc...
</VirtualHost>
1
  • Sry my vote score is low so formatting is not allowed for me yet.
    – vic
    Mar 27, 2014 at 9:50
0

I know I'm really late to the party but it shows on the very top in the search engine when I was looking for the answer. This one works like a charm for me:

<VirtualHost YOUR.SERVERS.IP.HERE:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .