Home > Net >  Elastic Beanstalk - Denying access to directory/subdirectory (Nginx)
Elastic Beanstalk - Denying access to directory/subdirectory (Nginx)

Time:04-14

My environment:
Platform: PHP 8.0 running on 64bit Amazon Linux 2/3.3.12
Proxy server: Nginx

What I need:
To deny access to the /img directory and its files.

What I've tried:

1.Creating this folder in the root of my source code: .ebextensions

2.Adding a newconf.config file with the following content into the folder above:

files:
    "/etc/nginx/conf.d/my_conf.conf":
        mode: "000644"
        owner: root
        group: root
        content: |
           location /img {
               return 403;
           }

3.Upload & deploy in Elastic Beanstalk.

Outcome:
There's no error message but I'm still able to access the /img directory because my_conf.conf isn't created in /etc/nginx/conf.d/.

Remarks:
I'm open other solutions that will help block access to the /img directory.

Solution:
So Marcin was partly right about the path but it was crucial in helping me find the solution.

If you place it in .platform/nginx/conf.d/, you might get this error during deployment: "location" directive is not allowed here

So here's what needs to be done:

1.Create a directory of .platform/nginx/conf.d/elasticbeanstalk/ in your source code.

2.Create a conf file and put your configs in it. In my case I'm using my_conf.conf :

location /img {
    return 404;
}

3.Upload & deploy.

That's it. I got the solution here. Do note the link is in Japanese and I had to use a translator.

CodePudding user response:

You are using 64bit Amazon Linux 2/3.3.12. Thus your nginx settings should be located in .platform/nginx/conf.d/ (not .ebextensions) as explained in the docs.

You can try with .platform/nginx/conf.d/my_conf.conf with the content of:

location /img {
     return 403;
}
  • Related