我目前正在运行 CentOS,它托管我的 web 和 gitlab 服务器,以及托管 subsonic 服务器的 Windows 计算机。目前,我的 IP 指向 CentOS,但无法正确重定向。尽管我进行了设置,但我能够访问 / 但无法访问具有子域的任何其他站点,因此我想知道我哪里出错了以及如何纠正该问题。当人们输入时,http://git.example.com
它是否也有可能自动重定向到https://git.example.com
?提前致谢!
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>
答案1
你之间存在不匹配
NameVirtualHost *:80
和
<VirtualHost *>
您需要将 更改为VirtualHost
与 相同 NameVirtualHost
,即
<VirtualHost *:80>
至于重定向,vic的回答应该有帮助——如果没有,看看在 Apache 中重定向、更改 URL 或将 HTTP 重定向到 HTTPS - 您想了解但又不敢问的有关 Mod_Rewrite 规则的一切
答案2
使用这些对我有用的规则:
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]
注意:删除带有 https 链接的 ()。这些是我的配置:
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>
答案3
我知道我来晚了,但当我寻找答案时,它出现在搜索引擎的最顶部。这个对我来说非常有效:
<VirtualHost YOUR.SERVERS.IP.HERE:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>