S
S
Sergey Nikiforov2017-11-04 12:19:02
symfony
Sergey Nikiforov, 2017-11-04 12:19:02

How to properly set up a redirect from http to https in Symfony 3?

Good afternoon! Set up a redirect to https via nginx:

server {
  location / {
    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
      try_files $uri $uri/ @fallback;
    }
    location / {
      try_files /does_not_exists @fallback;
    }
    location ~ [^/]\.ph(p\d*|tml)$ {
      try_files /does_not_exists @fallback;
    }
  }
  location @fallback {
    error_log /dev/null crit;
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    rewrite ^(.*)$ https://site.ru$1 permanent;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Port $server_port;
    access_log off ;
    proxy_redirect http://127.0.0.1:8080 /;
  }
  listen [ip address]::80;
}
server {
  location / {
    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
      try_files $uri $uri/ @fallback;
    }
    location / {
      try_files /does_not_exists @fallback;
    }
    location ~ [^/]\.ph(p\d*|tml)$ {
      try_files /does_not_exists @fallback;
    }
    
  }
  location @fallback {
    error_log /dev/null crit;
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Port $server_port;
    access_log off ;
    proxy_redirect http://127.0.0.1:8080 /;
  }
  listen [ip address]:443;
}

The redirect works, but in Symfony I use LiipImageBundle, it generates links to images that go through http. I don't understand how to make it work via https. I set schema: [https] in the routes settings, so it ends up endlessly looping. I think because of the mixed content there is a problem with sending a letter through smtp.yandex.ru. Help me to understand

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2017-11-04
@Arik

You can configure the current server (nginx section) completely under 443 and separately for these domains raise the server for port 80, there already redirect to https

server {
    listen 80;
    server_name example.com www.example.com *.example.com;
#    listen [::]:80;

    access_log off;

    #include acme;?

    location / {
        return 301 https://example.com$request_uri;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question