Issue
- How to configure the redirect of each HTTP status outside Liferay with Nginx.
- Inside Liferay you are able to manage some related behaviors:
- You can define a redirect to a page on 404 errors with the following property:
-
sites.friendly.url.page.not.found=/html/portal/404.html
-
- Or show the HTTP status with the following property:
-
layout.show.http.status=true
-
- You can define a redirect to a page on 404 errors with the following property:
- With DXPCloud is posible to manage this HTTP 404 and the others HTTP status from the Webserver.
Environment
- Liferay PaaS
Resolution
- Nginx is able to intercept the HTTP errors and serve a static page:
- To enable this feature just need to add the
proxy_intercept_errors on;
flag to the webserver config file. - After that, remap each error with their html page and their PATH.
- To enable this feature just need to add the
- As an example, this configuration redirects the HTTP 404 error:
- Note for Liferay Cloud stack version 4.x: Since the root location is being customized, the file name must be
liferay.conf
to override the defaultliferay.conf
.
- Note for Liferay Cloud stack version 4.x: Since the root location is being customized, the file name must be
location / {
# auth_basic "Authentication Required";
# auth_basic_user_file /var/www/html/.htpasswd;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_pass http://127.0.0.1:81;
proxy_intercept_errors on;
error_page 404 /code404.html;
location = /code404.html {
root /var/www/html/;
internal;
}
}
Additional Information
- Liferay Cloud stack version 4.x - Webserver Service Changes
- Nginx flags configuration
- Nginx HTTP error page configuration
- This article explains how to redirect to a custom page for 404 code, inside Liferay.