Score:0

nginx reverse proxy sending links in http

cn flag

I have an nginx reverse proxy running based on the working setup here. It is sending the page to our backend (apache) correctly except the page comes back with all links in http (page itself is https). I know that the configuration change needs to be done on the backend (apache), I just don't know where.

Here is my original setup:

    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 config

    <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>
us flag
Please add full details of the setup to this question.
cn flag
I ended up adding the line "add_header 'Content-Security-Policy' 'upgrade-insecure-requests';" to my location directive which seems to have fixed it. Is this the correct way to set this up?
us flag
No, you need to configure whichever software is generating those links to create proper links.
cn flag
Ok, I'll look into that. Thanks for the help
cn flag
Just to update, Tero's answer was correct. I updated the perl module creating the links to get it working.
Score:0
pk flag

Use return instead of rewrite.

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

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.