【问题标题】:How to configure apache ssl with reverse proxy如何使用反向代理配置 apache ssl
【发布时间】:2018-06-16 02:00:05
【问题描述】:

我有一个烧瓶应用程序在端口 8080 上运行,我想使用 Apache 作为反向代理并将 http 重定向到 https。

"/etc/apache2/sites-enabled/example.conf"

<VirtualHost *:80>
    ServerAdmin support@example.com
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent / https://example.com/ 
</VirtualHost>

<VirtualHost *:443> 
    ServerName example.com
    ErrorLog /home/helloworld/logs/error.log
    CustomLog /home/helloworld/logs/access.log combined

    SSLEngine on
    SSLCertificateFile /home/helloworld/certs/cert.pem
    SSLCertificateKeyFile /home/helloworld/certs/key.pem

    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>

我也有一个工作的 nginx 配置来做同样的事情,但我想在生产中使用 apache。 这是nginx配置

server {
    listen 80;
    server_name _;
    location / {
        return 301 https://$host$request_uri;
    }
}
server {
    listen 443 ssl;
    server_name _;

    ssl_certificate /home/helloworld/certificate/cert.pem;
    ssl_certificate_key /home/helloworld/certificate/key.pem;

    access_log /var/log/ex_access.log;
    error_log /var/log/ex_error.log;

    location / {
        proxy_pass http://localhost:8080;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

【问题讨论】:

  • 测试时会发生什么(您的配置看起来不错)?

标签: apache ssl nginx reverse-proxy


【解决方案1】:

而不是只匹配 / 的 Redirect ,这应该更好(但还有其他方法可以做到这一点):

RewriteEngine On
RewriteRule ^/.*$ http://example.com/$1 [R=301,L]

【讨论】:

    猜你喜欢
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 2010-09-21
    • 2017-10-24
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多