Score:1

How to display custom "Access Denied" page when an user tries to view a page that doesn't exist in nginx web server?

qa flag

I created a new file /usr/share/html called access-denied.html. It contains "Access denied".

I've apache server running at port 8080 and nginx is running at port 80. I'm using nginx as a reverse proxy server.

server{
listen 80;
server_name test-reverse-proxy.com ;
location / {
proxy_pass http://192.168.169.149:8080/;
}
location /access-denied{
root /usr/share/nginx/html/access-denied.html;
try_files /access-denied.html =404;

}

}

Currently when I enter something except / in the browser, for example http://192.168.169.149/dffdsf I get 404 Not Found.

I want this to be replaced by "Access Denied".

How do I do it?

Score:0
ws flag

First write a working config without the special behaviour (what you've shown us here won't work even if you remote the access-denied location block.

Secondly, returning a "access-denied" message is somewhat pointless if its accompanied by a 404 status.

error_page 403 404 =403 /access-denied.html;
root /usr/share/nginx/html/;

location / {
...
achhainsan avatar
qa flag
This doesn't work!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.