Issue
- When user hits the 'http://example.com' it should be redirected to the 'https://example.com' URL.
Environment
- Liferay PaaS
Resolution
-
By default, the Nginx service uses the below snippet in the 'Nginx configuration' file which automatically redirects the domain from HTTP to HTTPS.
if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; }For example:
server { listen 80; server_name example.com; if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; } }server { listen 80; server_name www.example.com; if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; } }
Additional Information
-
URL Redirects
- Ensure that HTTP-to-HTTPS redirects first direct to a secure version of the same original site, to prevent man-in-the-middle redirects to malicious sites. Ensure that redirects never point to HTTP addresses. The configure URL redirects via your environment’s Nginx configuration file.
-
Web Server Service (Nginx)
-
For PaaS environments, files in
/webserver/configs/[ENV]/are copied as overrides into/etc/nginx/in the web server container in Liferay Cloud. Files in/webserver/configs/[ENV]/public/are copied as overrides intovar/www/html/. -
And, as of web server version 6.0.0+, the
nginx.conffile does not allow configurations that require root user permissions. Reference: Changes to the Web Server Service
-