我是新手,但是我已经挣扎了一段时间,我肯定做错了。
我们使用Apache 2.4作为内部网页的前端。
当我尝试将请求转发到80以外的端口时,它会发疯并重定向几次 http://demos.company.com/demos.company.com/demos.company.com/demos.company.com/demos.company.com/demos.company.com/demos.company.com/[...]/demos.company.com/WebApplicationFail
的httpd.conf:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
<VirtualHost *:80>
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule ^(.*) %{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "C:/Program Files/Apache24/conf/ssl/company.crt"
SSLCertificateKeyFile "C:/Program Files/Apache24/conf/ssl/company.key"
SSLCertificateChainFile "C:/Program Files/Apache24/conf/ssl/CA.pem"
# Proxy configuration
ProxyPreserveHost On
ProxyRequests Off
ServerName demos.company.com
ProxyPass /WebApplicationOK http://10.0.0.160/WebApplicationOK
ProxyPassReverse /WebApplicationOK http://10.0.0.160/WebApplicationOK
ProxyPass /WebApplicationFailRoute http://10.0.0.125:8000/WebApplicationFail
ProxyPassReverse /WebApplicationFailRoute http://10.0.0.125:8000/WebApplicationFail
</VirtualHost>
我们需要维护每个http请求重定向到https。
如果可能,我们需要互联网地址“https://demos.company.com/ThisContext”显示内部网“http://10.0.0.125:8000/OtherContext”。
提前致谢。
答案 0 :(得分:1)
我知道了,实际上很简单。您只需将这些行从下面重定向到您的ssl.conf即可
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName XXXX.ddns.net
# These are your SSL settings; your responsibility
SSLCertificateFile /etc/letsencrypt/live/XXXX.ddns.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/XXXX.ddns.net/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
# Your document root; where the JavaScript application lives
DocumentRoot /var/www/html
<Directory /var/www/html/ >
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride None
Order Allow,Deny
Allow From All
</Directory>
# Reverse proxy settings for API (custom redirection https to specific port)
ProxyRequests Off
ProxyPreserveHost On
<Location /api >
ProxyPass http://127.0.0.1:3000/api
ProxyPassReverse http://127.0.0.1:3000/api
</Location>
</VirtualHost>
答案 1 :(得分:0)
这是为复杂的任务添加复杂指令的问题。
你有一个使用端口80的虚拟主机,为什么要检查SSL?,它将收到的所有内容都不是SSL。
重写指令也缺少方案。
所以只是:
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [R,L]
如果您不需要使用变量,对于可变主机名,我会更简单:
Redirect / https://whateverhost.example.com/
在httpd中成功的规则:始终使用最简单的选项。