{"id":8605,"date":"2024-06-17T09:43:23","date_gmt":"2024-06-17T09:43:23","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=8605"},"modified":"2024-08-05T07:56:27","modified_gmt":"2024-08-05T07:56:27","slug":"deny-url-access-in-odoo-with-nginxs-custom-404-error-page","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/deny-url-access-in-odoo-with-nginxs-custom-404-error-page\/","title":{"rendered":"Deny URL Access in Odoo with Nginx&#8217;s Custom 404 Error Page"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 2,736<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p>To deny specific URL access in an Odoo web application using Nginx and serve Odoo&#8217;s custom 404 error page instead, you can follow these steps. This approach involves configuring Nginx to intercept requests to specific URLs and respond with a 404 error, while using Odoo&#8217;s custom 404 error template for a consistent user experience.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Deny URL Access and Serve Custom 404 Error Page<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Locate or Create Odoo&#8217;s Custom 404 Error Page<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure Odoo has a custom 404 error template. Typically, Odoo&#8217;s default 404 page is located in the <code>addons\/web\/views<\/code> directory (e.g., <code>404.xml<\/code> or <code>404.html<\/code>).<\/li>\n\n\n\n<li>If you want a specific custom 404 page, you can create or modify the existing one.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Configure Nginx to Serve 404 Error for Specific URLs<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Update your Nginx configuration file to intercept the specific URLs you want to deny and return a 404 status code.<\/li>\n\n\n\n<li>Use Nginx&#8217;s <code>location<\/code> directive to match the specific URLs or patterns.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Map Nginx&#8217;s 404 Handling to Odoo&#8217;s Custom 404 Page<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure Nginx serves Odoo&#8217;s custom 404 page when a 404 error is returned.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Detailed Configuration Steps<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. Modify Nginx Configuration<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Open Your Nginx Configuration File<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Typically, the configuration file is located at <code>\/etc\/nginx\/nginx.conf<\/code> or <code>\/etc\/nginx\/sites-available\/default<\/code>.<\/li>\n\n\n\n<li>You might have a specific configuration file for your Odoo site in <code>\/etc\/nginx\/sites-available\/<\/code> or <code>\/etc\/nginx\/conf.d\/<\/code>.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Add Location Blocks for URL Denial<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Define <code>location<\/code> blocks for each URL or URL pattern you want to deny access to.<\/li>\n\n\n\n<li>Use <code>return 404<\/code> to immediately respond with a 404 status for these URLs. Example configuration to deny access to <code>\/secret<\/code> and any URL pattern starting with <code>\/private<\/code>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   server {\n       listen 80;\n       server_name yourdomain.com;\n\n       # Existing Odoo server configuration\n       location \/ {\n           proxy_pass http:\/\/127.0.0.1:8069;\n           proxy_set_header Host $host;\n           proxy_set_header X-Real-IP $remote_addr;\n           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n           proxy_set_header X-Forwarded-Proto $scheme;\n           proxy_redirect off;\n       }\n\n       # Deny access to specific URLs\n       location = \/secret {\n           return 404;\n       }\n\n       location ~ ^\/private\/ {\n           return 404;\n       }\n\n       # Error page handling\n       error_page 404 \/custom_404_page;\n\n       location = \/custom_404_page {\n           # Serving the custom 404 page from Odoo\n           proxy_pass http:\/\/127.0.0.1:8069\/404;\n           proxy_set_header Host $host;\n           proxy_set_header X-Real-IP $remote_addr;\n           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n           proxy_set_header X-Forwarded-Proto $scheme;\n       }\n   }<\/code><\/pre>\n\n\n\n<p>In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>location<\/code> block for <code>\/secret<\/code> and <code>\/private\/*<\/code> immediately returns a 404 error.<\/li>\n\n\n\n<li>The <code>error_page<\/code> directive maps 404 errors to a custom page served by Odoo.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. Reload Nginx<\/h4>\n\n\n\n<p>After making the changes to your Nginx configuration file, you need to reload Nginx to apply the new settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nginx -t\nsudo systemctl reload nginx<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>nginx -t<\/code> command tests the configuration file for syntax errors.<\/li>\n\n\n\n<li>If there are no errors, <code>systemctl reload nginx<\/code> will reload the configuration without restarting the server.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Tips<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Custom 404 Page Styling<\/strong>: Ensure that the custom 404 page served by Odoo is styled according to your web application\u2019s theme for a seamless user experience.<\/li>\n\n\n\n<li><strong>Performance Considerations<\/strong>: For high-traffic sites, consider caching the 404 responses to reduce load on the Odoo backend.<\/li>\n\n\n\n<li><strong>Security<\/strong>: Avoid exposing sensitive information in the URL patterns or 404 pages. Keep the denied URLs and custom 404 pages generic to avoid leaking system details.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Implementing Nginx&#8217;s custom 404 error page to deny URL access in <a href=\"https:\/\/www.infinitivehost.com\/managed-odoo-server-solutions\"><strong><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">Odoo server solution<\/mark><\/strong><\/a> is an effective way to increase security and control access. You can follow all of these steps, including configuring the Nginx to handle specific URL denials and redirecting to Odoo\u2019s custom 404 error page. This method enables you to tailor access control and error handling in your Odoo web application while leveraging the power and flexibility of Nginx as your web server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2,736 Views To deny specific URL access in an Odoo web application using Nginx and serve Odoo&#8217;s custom 404 error page instead, you can follow these steps. This approach involves configuring Nginx to intercept requests to specific URLs and respond with a 404 error, while using Odoo&#8217;s custom 404 error template for a consistent user [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[203],"tags":[],"class_list":["post-8605","post","type-post","status-publish","format-standard","hentry","category-odoo"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=8605"}],"version-history":[{"count":2,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8605\/revisions"}],"predecessor-version":[{"id":8837,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8605\/revisions\/8837"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=8605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=8605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=8605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}