'Nginx throws - 403 Forbidden
I am using nginx docker image to host a static site behind basic authentication on ECS. The site contains landing page, along with a list of directories having index.html and linked in main landing page.
With current configuration I am able to access index.html in other directories but not main landing page at location - /. When I try to access it at location /, nginx throws - 403 forbidden.
Following is my Dockerfile and nginx.conf file :-
Dockerfile
FROM nginx:1.21.4
RUN useradd new-user
RUN chown new-user:new-user /usr/share/nginx/html/
RUN rm -v /etc/nginx/conf.d/default.conf
ADD nginx/ /etc/nginx/conf.d/ # => nginx folder contains nginx.conf and nginx.htpasswd file
COPY index.html /usr/share/nginx/html/
RUN mkdir /usr/share/nginx/html/static
COPY static/ /usr/share/nginx/html/static/
EXPOSE 80
VOLUME ["/usr/share/nginx/html/"]
CMD ["nginx", "-g", "daemon off;"]
nginx.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
# basic user authentication
auth_basic "basic-auth";
auth_basic_user_file /etc/nginx/conf.d/nginx.htpasswd;
}
location /lb-status {
access_log off;
return 200;
}
location /static {
access_log off;
alias /usr/share/nginx/html/static;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
I have cross checked my configuration from official docs and few answers on StackOverflow. I am unable to find the issue with current config. Would appreciate any hint.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
