We have a symfony project deployed and working ok but now we want to enable https.
We created and enabled another virtualhost like this:
<VirtualHost *:443>
ServerName project.domain.net
DocumentRoot /home/user/dev/project/web
<Directory /home/user/dev/project/web>
AllowOverride All
Require all granted
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeScript assets
<Directory /home/user/dev/project>
Options FollowSymlinks
</Directory>
ErrorLog /var/log/apache2/project.test_error.log
CustomLog /var/log/apache2/project.test_access.log combined
SSLEngine on
SSLCertificateChainFile /ssl/cert.pem
SSLCertificateKeyFile /ssl/private.key
SSLCertificateFile /ssl/wildcard.crt
We can navigate to https://project.domain.net and it seems ok but when we check
$request->getUri();
the result is http://project.domain.net, so it is http instead of https.
Why is that? how to fix?
UPDATE: We added the config given by @Leroy and the result is:
HTTP_X_FORWARDED_PROTO https
REQUEST_METHOD GET
REQUEST_SCHEME http
SERVER_NAME zerbikatdesa.sare.gipuzkoa.net
SERVER_PORT 80
and the $request->getUri still returns the http insted of https
CodePudding user response:
Usually applications must determine themselves which urls require ssl. In symfony you can configure routes to require ssl. Then the application can force ssl on those pages. But based on your request, all of your pages should be https.
Symfony uses 2 ways to determine if a route is secure. When you are behind a proxy, like a loadbalancer, you have to allow that proxy in the trusted_proxies
and trusted_headers
(usually there are env variables for you to configure). The proxy should also send a header that the page is loaded over https.
If you are not behind a proxy, like you do by defining a second vhost directing to the filesystem, you have to tell symfony a route is loaded over https. The same request header should be passed to the application.
So the following should fix it.
<VirtualHost *:443>
RequestHeader set X-Forwarded-Proto https
</VirtualHost>
I also see you are using the /web
subdirectory for public access. Are you still using Symfony version 2?
CodePudding user response:
Add this lines to your config file and restart the server:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
For more detail: http://www.sslshopper.com/apache-redirect-http-to-https.html