nginx 反向代理在 http 中发送链接

nginx 反向代理在 http 中发送链接

我有一个基于工作设置运行的 nginx 反向代理这里。它正确地将页面发送到我们的后端(apache),但页面返回时所有链接都是 http(页面本身是 https)。我知道需要在后端(apache)上进行配置更改,但我不知道在哪里。

这是我的原始设置:

    server {
listen 80;
server_name example.com;

rewrite ^(.*) https://$server_name$1 permanent;
 }
    server {
listen 443;
server_name example.com;

root   /var/web/;

ssl                  on;
ssl_certificate /etc/apache2/ssl/server.crt;
ssl_certificate_key /etc/apache2/ssl/server.key;

# -----------------------------------------------------------------
# https://mozilla.github.io/server-side-tls/ssl-config-generator/
# generate with openssl dhparam -out dhparams.pem 2048
ssl_dhparam /etc/apache2/ssl/dhparam.pem;


ssl_prefer_server_ciphers on;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;

# Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
#ssl_dhparam /etc/pki/nginx/dh2048.pem;

# intermediate configuration. tweak to your needs.
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';

location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
}

}

Apache 配置

    <VirtualHost *:8080>
    ServerName localhost:8080
    ServerAlias 127.0.0.1:8080
    DocumentRoot /var/web/
    DirectoryIndex index.html index.xhtml
# - absorb the shared virtual host settings
    </VirtualHost>

答案1

使用return而不是rewrite

server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

相关内容