Apache Redirect To Another Server with subdomain
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
Related videos on Youtube
Hong Yi
Updated on September 18, 2022Comments
-
Hong Yi almost 2 years
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 tohttps://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>
-
vic over 10 yearsSry my vote score is low so formatting is not allowed for me yet.
-
Hong Yi over 10 yearsshouldn't i be using proxy instead of mod_rewrite? when should i be using proxy instead?
-
Hong Yi over 10 yearsi 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?
-
Jenny D over 10 yearsYou asked how to redirect
http://git.example.com
tohttps://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 tohttps://git.example.com
. -
Hong Yi over 10 yearshow about the proxy of music.comapny.com to the other server? I can't seem to get it working. :/
-
Jenny D over 10 years"Can't seem to get it working" is insufficient data. What do your logs say? Please add that information to the question.