Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
NGINX HTTP Server

You're reading from   NGINX HTTP Server Harness the power of NGINX with a series of detailed tutorials and real-life examples

Arrow left icon
Product type Paperback
Published in May 2024
Publisher Packt
ISBN-13 9781835469873
Length 262 pages
Edition 5th Edition
Languages
Tools
Concepts
Arrow right icon
Authors (3):
Arrow left icon
Martin Bjerretoft Fjordvald Martin Bjerretoft Fjordvald
Author Profile Icon Martin Bjerretoft Fjordvald
Martin Bjerretoft Fjordvald
Gabriel Ouiran Gabriel Ouiran
Author Profile Icon Gabriel Ouiran
Gabriel Ouiran
Mr. Clement Nedelcu Mr. Clement Nedelcu
Author Profile Icon Mr. Clement Nedelcu
Mr. Clement Nedelcu
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Part 1:Begin with NGINX FREE CHAPTER
2. Chapter 1: Downloading and Installing NGINX 3. Chapter 2: Basic NGINX Configuration 4. Part 2: Dive into NGINX
5. Chapter 3: Exploring the HTTP Configuration 6. Chapter 4: Exploring Module Configuration in NGINX 7. Chapter 5: PHP and Python with NGINX 8. Chapter 6: NGINX as a Reverse Proxy 9. Part 3: NGINX in Action
10. Chapter 7: Introduction to Load Balancing and Optimization 11. Chapter 8: NGINX within a Cloud Infrastructure 12. Chapter 9: Fully Deploy, Manage, and Auto-Update NGINX with Ansible 13. Chapter 10: Case Studies 14. Chapter 11: Troubleshooting 15. Index 16. Other Books You May Enjoy

Looking at the 403 forbidden custom error page

If you decide to use allow and deny directives to allow or deny access, respectively, to a resource on your server, clients who are being denied access will usually fall back on a 403 Forbidden error page. Imagine you have carefully set up a custom, user-friendly 403 error page for your clients to understand why they are denied access. Unfortunately, you cannot get that custom page to work, and clients still get the default NGINX 403 error page:

server {
    [...]
    allow 192.168.0.0/16;
    deny all;
    error_page 403 /error403.html;
}

The problem is simple: NGINX also denies access to your custom 403 error page! In such a case, you need to override the access rules in a location block specifically matching your page. You can use the following code to allow access to your custom 403 error page only:

server {
    [...]
    location / {
        error_page 403 /error403.html;
        allow 192.168.0.0/16;
        deny all;
    }
    location = /error403.html {
        allow all;
    }
}

If you are going to have more than just one error page, you could specify a location block matching all error page filenames:

server {
    [...]
    location / {
        error_page 403 /error403.html;
        error_page 404 /error404.html;
        allow 192.168.0.0/16;
        deny all;
    }
    location ~ "^/error[0-9]{3}.html$" {
        allow all;
    }
}

All your visitors are now allowed to view your custom error pages.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image